while循环:
public static void main(String[] args) {
int sum = 1;
int i = 9; //计算X的阶乘,将此处9换成X即可(X为任意正整数)
while( i>0) {
sum *= i;
i--;
}
System.out.println(sum);
}
for循环:
public static void main(String[] args) {
int sum = 1;
for(int i=9;i>0;i--){ //计算X的阶乘,将此处i=9换成i=X即可(X为任意正整数)
sum *= i;
}
System.out.println(sum);
}