java的一经典教程

源代码在线查看: factorial.txt

软件大小: 6741 K
上传用户: jill
关键词: java 教程
下载地址: 免注册下载 普通下载 VIP

相关代码

				// 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);
				   }
				}
							

相关资源