java1到10的阶乘
时间: 2024-02-26 15:59:26 浏览: 65
JAVA实现1到10的阶乘 ............
5星 · 资源好评率100%
Java中可以使用循环来计算阶乘,以下是1到10的阶乘的Java代码:
```java
public class Factorial {
public static void main(String[] args) {
for (int i = 1; i <= 10; i++) {
int factorial = 1;
for (int j = 1; j <= i; j++) {
factorial *= j;
}
System.out.println(i + "! = " + factorial);
}
}
}
```
输出结果为:
```
1! = 1
2! = 2
3! = 6
4! = 24
5! = 120
6! = 720
7! = 5040
8! = 40320
9! = 362880
10! = 3628800
```
阅读全文