相关代码 |
|
// Program to compute the factorial of a // number entered by the user import javax.swing.JOptionPane; public class Factorial { public static void main(String[] args) { int fact = 1; String numStr; numStr = JOptionPane.showInputDialog( "Enter a value for n: " ); int n = Integer.parseInt(numStr); while (n > 0) { fact *= n; n--; } JOptionPane.showMessageDialog(null, numStr + "! = " + fact); System.exit(0); } }
相关资源 |
|