面向对象程序设计3
app.java:
import factorial.Computer;
import java.util.*;
public class App {
public static void main(String[] args) {
System.out.print("请输入n的值:");
Scanner input = new Scanner(System.in);
int n = input.nextInt();
Computer count = new Computer();
n = count.inputcount(n);
System.out.println("阶乘为:"+n);
}
}
Computer :
package factorial;
public class Computer {
int count = 1;
public int inputcount(int n) {
for (int i = 1; i<=n; i++) {
count = count * i;
}
return count;
}
}
运算结果: