When I try running this code in netbeans, I get a window which says that the main class wasn't found in PerfectNumbers.
And underneath there's a select main class, which endlessly stays at : Initializing view, please wait...
public class PerfectNumbers
{
int nbToFound;
public PerfectNumbers(int nb)
{
nbToFound = nb;
}
public void findPerfects()
{
int nb = 0;
int from = 2;
while(nb < nbToFound) {
from++;
if(isPerfect(from)) {
System.out.println(from + " is perfect");
nb++;
}
}
}
boolean isPerfect(int num) {
int sum = 1;
for(int i = 2; i <= num/2; i++) {
if(num % i == 0) {
sum += i;
if(sum > num)
return false;
}
}
return sum == num;
}
public static void main (String[] args)
{
PerfectNumbers perfect = new PerfectNumbers(4);
perfect.findPerfects();
}
}