实验三
一、用for循环输出n的阶乘
package hello;
public class for{
public static void main(String[] args) {
int n,i=1,sum;
for(i=1;i<=n;i++)
{
sum=sum*i;
} System.out.print("sum="+sum);
}
二、用while语句输出n的阶乘
package hello;
public class while{
public static void main(String[] args) {
int i=1,mul=1;
while(i<=100)
mul=mul*i;
i++;
System.out.printIn(“i的阶乘=”+mul);
}
}
三、用do-while输出n的阶乘
public class dowhile{
public static void main(String[] rags)
{ int i=1,jc=1;
do{
jc=jc*i,
i++;
}
while(i<100);