import javax.swing.*;
/**
*这是计算n的阶乘
*通过了do...while来实现
* @author jie
*
*/
public class FactorialTest {
public static void main (String args[])
{
int n;
String s=(String)JOptionPane.showInputDialog(null,"请输入整数n","1到n的阶乘",
JOptionPane.PLAIN_MESSAGE,null,null,null);
n=Integer.parseInt(s);//有人不明白这是什么来的,这相当于一种固定的语法结构,我是这样理解的,记住就行
{
int i=1,j=1,k=1;//int型只要2^31—1个数
do
{
k*=j;
j++;//循环体结构
}while(j<=n);//条件判断
System.out.println(n+"!="+k);
}
}
}
第七周作业3:循环大战!
最新推荐文章于 2015-06-30 10:00:50 发布