public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
int x, i, sum;
System.out.print("Enter x: ");
x = input.nextInt();
sum = 0;
for ( i = 1; i < x; i++ )
{
if ( x%i == 0 )
sum = sum + i;
}
if ( sum == x )
System.out.println("perfect number");
}
|
Instead of reading in a number x and check if the number is a perfect number, we want to change the program so it can find all the perfect numbers from 1 to 1,000,000.
You can do so by testing each of the numbers from 1 to 1,000,000.
For the assignment, make changes to the above program so it will print out all the perfect numbers that are between 1 and 1,000,000.
Your program is correct if you see these 4 numbers printed: 6, 28, 496 and 8128