// Find all perfect numbers less than // or equal to then entered upper bound. // Use a method sumFactors that finds the sum of // the factors of the input. import javax.swing.JOptionPane; public class Perfect2 { public static void main(String[ ] argv) { int upperBound, n; upperBound = Integer.parseInt(JOptionPane.showInputDialog( "Enter upper bound for perfect number search")); for(n = 2; n <= upperBound; n++) if (n == sumFactors(n)) System.out.println(n); } public static int sumFactors(int n) { int sum = 0; for(int factor = 1; factor <= n / 2; factor++) if (n % factor == 0) sum += factor; return sum; } } // Prompt of input dialog: Upper bound for perfect number search: // Sample input to input dialog: 10000 // Output in Terminal Window: 6 28 496 8128