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

}

运算结果:
面向对象程序设计3_第1张图片

你可能感兴趣的:(面向对象程序设计3)