// calculating factorials using a "for" loop import javax.swing.JOptionPane; public class Factorials { public static void main( String[] args ) { int number, index; /*this will work up to 16*/ int result = 1; // Prompt the user to enter the number to caluclate String numString1 = JOptionPane.showInputDialog(null, "Enter an integer from 2 - 16 ", "Input Number Window", JOptionPane.QUESTION_MESSAGE); // Convert the string into an int value number = Integer.parseInt(numString1); if (number > 1 && number < 17) { for (index = 1; index <= number; index++) { result = result * index; } System.out.println("The factorial is " + result); } else { System.out.println(number + " is not a valid number for this computation."); } System.exit( 0 ); } // end main } // end of program