View Single Post
  #2 (permalink)  
Old 11-22-2008, 09:23 AM
Lite3864 Lite3864 is offline
Member
 
Join Date: Nov 2008
Posts: 3
Rep Power: 0
Lite3864 is on a distinguished road
Default
I am getting closer now I just need to figure out how to get rid of the 1 and get the 6 back. 1 is not a perfect number but 6 is. Here is what I have now.

public class Perfect
{
public static void main (String[ ] args)
{


Scanner keyboard = new Scanner(System.in);

int limit;

System.out.println("Please enter a limit for finding perfect numbers:");
limit = keyboard.nextInt();

for (int i=1; i<= limit; i++)
{
int sum=0;
for (int j=1; j<=Math.ceil(Math.sqrt(i)); j++)
{
if (i%j==0)
{
sum+=j;
//System.out.println(i+"i"+j+"j"+i/j+"t"+sum);
if ((i/j)>Math.floor(Math.sqrt(i))&& (i/j)<i)
sum+=(i/j);
}
}
if (sum==i) System.out.println(i);
}


}//end main method
}//end class
Reply With Quote