Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Ernesta Fernandez   on Apr 14 In Java Category.

  
Question Answered By: Phoebe Brown   on Apr 14

public class PerfectNumberGenerator{

private static int max = 1000;

public static void main(String[] args){
for (int i = 1;i <= max; i++){
if (isPerfect(i)){
System.out.println(String.valueOf(i) + " is perfect.");
}
}
}

public static boolean isPerfect(int n){
int sum = 0;
for (int i = 1; i < n; i++){
if (n%i == 0) sum = sum + i;
}
return (sum == n);
}
}

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Logic error Or get search suggestion and latest updates.


Tagged: