Alright. Ive been at this problem for a few days know and cant figure out what's wrong with my coding.

The Problem: Create a method called displayPerfectNumber in your own class named myMath. The method displayPerfectNumber asks a user to enter a integer number and displays every perfect number from 1 to the input integer number. A perfect number is one that equals the sum of all the numbers that divides evenly to into it. For example, 6 is perfect because 1,2 and 3 divide evenly into it, and their sum is 6; however, 12 is not a perfect number because 1,2,3,4, and 6 divide evenly into it, and their sum is greater than 13. Write a main method to call the method displayPerfectNumber.

Sample output

Input a integer number:

1000

The perfect number from 1 to 1000:

6

28

496

My Coding:

```
import java.util.Scanner;
public class MyMath
{
public void displayPerfectNumber()
{Scanner input = new Scanner (System.in);
int num = 1;
int N;
System.out.println("Enter a perfect number");
N = input.nextInt();
while(num <= N)
{
int i = 1;
int sum = 0;
while(i < num)
{
if(num % i == 0)
{
sum = sum+1;
i = i + 1;
}
if (sum == num)
{
System.out.println("num" + num);
num = num + 1;
}
}
}
}
}
```

*Edited 3 Years Ago by Reverend Jim*: Fixed formatting