View Single Post
  #5 (permalink)  
Old 01-31-2008, 04:19 AM
jvasilj1 jvasilj1 is offline
Member
 
Join Date: Jan 2008
Posts: 26
jvasilj1 is on a distinguished road
Thanks a lot...My java code works now and i have jotptionpane working...I enter 10000 in the dialog box and it computes the perfect number up till 10000 and then the program ends...I need some help now in modifying my code to do that same procedure but just modify the math of it so it can compute AMICABLE NUMBERS....HERE IS MY CODE
--------------------------------------------------------------
Code:
import javax.swing.JOptionPane; public class AmicableNumbers { 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 amicable number search: // Sample input to input dialog: //10000 // Output in Terminal Window: //6 //28 //496 //8128
Reply With Quote