|
students needs help
i have created java code to give me perfect numbers, and it works...but now im hung up on modifying the main to give me AMICABLE NUMBERS. Any ideas???????
HERE IS MY PERFECT.JAVA CODE
----------------------------------------------
// Find all perfect numbers less than
// or equal to then entered upper bound.
import javax.swing.JOptionPane;
public class Perfect
{
public static void main(String[] args)
{
int upperBound, n, factor, sum;
upperBound = Integer.parseInt(JOptionPane.showInputDialog(
"Enter upper bound for perfect number search"));
for(n = 2; n <= upperBound; n++)
{
sum = 0;
for(factor = 1; factor <= n / 2; factor++)
if (n % factor == 0)
sum += factor;
if (n == sum)
System.out.println(n);
}
}
}
// Prompt of input dialog:
Upper bound for perfect number search:
// Sample input to input dialog:
10000
// Output in Terminal Window:
6
28
496
8128
|