当前位置 : 主页 > 手机开发 > 其它 >

面向对象程序设计3

来源:互联网 收集:自由互联 发布时间:2021-06-19
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 = ne

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;
    }

}

运算结果:

网友评论