编写程序,实现以下功能:求m!+(m+1)!+...+(n-1)!+n!。m和n的值从键盘输入,且m<n。Java
时间: 2024-06-14 11:05:22 浏览: 44
求N!的值.java
5星 · 资源好评率100%
以下是Java实现求m!+(m+1)!+...+(n-1)!+n!的程序:
```java
import java.util.Scanner;
public class FactorialSum {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入m的值:");
int m = scanner.nextInt();
System.out.print("请输入n的值:");
int n = scanner.nextInt();
int sum = 0;
int factorial = 1;
for (int i = m; i <= n; i++) {
factorial *= i;
sum += factorial;
}
System.out.println("结果为:" + sum);
}
}
```
阅读全文