1. 程式人生 > >java學習——構造類之3!+5!=126

java學習——構造類之3!+5!=126

image private clas int() code auto 學習 eth his

技術分享圖片

package my_project;

import java.util.Scanner;

public class my_first_class {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in = new Scanner(System.in);
        number x1 = new number();
        number x2 = new number();
        x1.setNum(in.nextInt());
        x2.setNum(in.nextInt());
        
int sum=x1.jieChen()+x2.jieChen(); System.out.println(x1.getNum()+ "! + "+x2.getNum()+"! = "+ sum); } } class number{ private int num; public int getNum() { return num; } public void setNum(int num) { this.num=num; }
public int jieChen() //沒有static是針對某一對象的 { int s=1; for(int i=1;i<=num;i++) { s=s*i; } return s; } }

java學習——構造類之3!+5!=126