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();
        }

}

NetBeans must be hung up then. Quit it and restart it. If you have more than one class in a project that has a main funtion, you need to specify which main to use. Do this by going into the project's properties under the "Run" category. Next to "Main Class", your present "main" class, if any, will be in the text box. If it's correct, there's nothing for you to do. If it's incorrect or blank, hit the "Browse" button and it will give you your options. Pick one for "main" and try running it.

Try hitting alt+f6. Then click ok if a window pops up.

I went ahead and circumvented it all by hitting, shift+F6

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.