IP- Program to find a given number is Perfect Number or not?

Objective: To find the given number is Perfect Number or not?


Program should accept a number through Net beans GUI, and on click of a button should find out a given number in a text field TFNum is Perfect Number or not.

What are Perfect Numbers?

Perfect Numbers are those numbers who's sum of individual factors is same as the number itself, with an  exception the number itself should not be included as one of the factors.

Net beans using Java Solution  along with a screen shot:
(Keeping in mind the students of class XI/XII having Informatics Practices as one of their subject)

Screen shot:
When you enter 9, for example which is not a perfect number:


when you enter 6, which is a perfect number:



private void BtnFindActionPerformed(java.awt.event.ActionEvent evt)
{                                     
        int n=Integer.parseInt(TFNum.getText());
        int sum=0;
for(int i = 1; i < n; i++)
        {
        if(n % i == 0)
        {
                sum = sum + i;
        }
        }
        if(sum == n)
        {
        TFAnswer.setText("YES");
        }
        else
        {
        TFAnswer.setText("NO");
        }
    } 

Other useful links:

1. Program to find a given number is perfect Number or not using pure java.

Popular posts from this blog

IP - Program to generate Fibonacci Series

Online Classes for Informatics Practices (Python) from Edukers by Pawan Arora