Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optional #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

optional #1

wants to merge 1 commit into from

Commits on Aug 4, 2016

  1. optional

    perfect number solution 
    
    
    public class PerfectNumber {
    	public static void main(String[] args) {
    		perfect(10000);
    	}
    	
    	//print all perfect numbers from 1 to n
    	public static void perfect(int n){
    	for (int i = 1; i<n; i++){
    		int comp = 0;
    		for (int j = 1; j<i; j++){
    			if (i%j == 0)
    				comp += j;	
    		}
    		if (comp == i)
    			System.out.println(i);
    		}
    	}
    	
    	//returns true or false if n is an "imperfect number"
    	//also includes perfect numbers
    	public static boolean imPerfect(int n){
    		int comp = 0;
    		for (int i = 1; i<n; i++){
    			if (n%i == 0)
    				comp += i;	
    		}
    		return (comp == n || comp == n+1 || comp == n-1 || comp == n+2 || comp == n-2);
    	}
    }
    NanNor committed Aug 4, 2016
    Configuration menu
    Copy the full SHA
    68833c9 View commit details
    Browse the repository at this point in the history