用java语句求N的阶乘
1.求10的阶乘。
public class Test {
public static void main(String[] args) {
int n = 10;
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
System.out.println(result);
}
}
2.用java语句求n的阶乘
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int result = 1;
for (int i = 1; i <= n; i++) {
result *= i;
}
System.out.println(result);
}
}