0 && num1 < 10) {..._2.输入一个小于10的正整数n,输出n的阶乘。">
赞
踩
public static void main(String[] args) {
int num1 = 1, sum1 = 1;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个小于10的正整数:");
num1 = scanner.nextInt();
if (num1 > 0 && num1 < 10) {
for (int i = 1; i <= num1; i++) {
sum1 *= i;
}
System.out.println(num1 + "的阶乘为:" + sum1);
} else {
System.out.println("输入不规范,请从新输入!");
}
scanner.close();
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。