用java编写程序求n!
发布网友
发布时间:2023-09-03 20:59
我来回答
共2个回答
热心网友
时间:2023-12-01 11:10
import java.util.Scanner;
public class Text{
public static void main(String args[]){
System.out.println("请输入n");
Scanner sc = new Scanner(System.in);
int n= sc.nextInt();
int t=1;
int i=1;
while(i<=n){
t=i*t;
i=i+1;
}
System.out.println("n!="+t);
}
}
//补充,JAVA文件保存时文件名必须和类名相同。
热心网友
时间:2023-12-01 11:10
import java.util.Scanner;
public class Test40002 {
public static void main(String[] args) {
int ri, repeat;
int i, n;
double fact;
Scanner in = new Scanner(System.in);
repeat = in.nextInt();
for (ri = 1; ri <= repeat; ri++) {
n = in.nextInt();
/*--------------------*/
fact = 1;
for(i = 1; i <= n; i++){
fact = fact * i;
}
/**** add ends */
System.out.println(fact);
}
}
}