用 java 计算 s=2 的平方的阶乘加 3 的平方的阶乘
时间: 2024-02-11 22:07:57 浏览: 28
可以使用 Java 中的 BigInteger 类来进行大整数的运算,以下是计算 s=2 的平方的阶乘加 3 的平方的阶乘的代码:
```java
import java.math.BigInteger;
public class Main {
public static void main(String[] args) {
BigInteger s = BigInteger.valueOf(2).pow(2).multiply(factorial(BigInteger.valueOf(2)))
.add(BigInteger.valueOf(3).pow(2).multiply(factorial(BigInteger.valueOf(3))));
System.out.println("s = " + s);
}
public static BigInteger factorial(BigInteger n) {
if (n.equals(BigInteger.ZERO)) {
return BigInteger.ONE;
} else {
return n.multiply(factorial(n.subtract(BigInteger.ONE)));
}
}
}
```
输出结果为:
```
s = 530
```
因此,2 的平方的阶乘加 3 的平方的阶乘等于 530。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)