面向对象程序设计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;
	}

}

运算结果:

posted on 2019-09-18 21:00  李基民  阅读(93)  评论(0编辑  收藏  举报