用java编写程序求n!
输入一个正整数repeat(0<repeat<10),做repeat次下列运算:读入1个正整数n(n<=50),计算并输出n!。例:括号内是说明输入3(repeat=2)...
输入一个正整数repeat (0<repeat<10),做repeat次下列运算:
读入1 个正整数 n(n<=50),计算并输出n! 。
例:括号内是说明
输入
3 (repeat=2)
1
10
5
输出
1.0
3628800.0
120.0
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();
/*--------------------*/
System.out.println(fact);
}
}
} 展开
读入1 个正整数 n(n<=50),计算并输出n! 。
例:括号内是说明
输入
3 (repeat=2)
1
10
5
输出
1.0
3628800.0
120.0
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();
/*--------------------*/
System.out.println(fact);
}
}
} 展开
展开全部
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 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文件保存时文件名必须和类名相同。
展开全部
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);
}
}
}
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);
}
}
}
本回答被提问者采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询