简单四则运算

class Arith{
	 private int num1,num2;
       Arith(){
    	   
       }
       Arith (int a,int b)
       {
    	   this.num1=a;
    	   this.num2=b;
       }
       
	public int getNum1() {
		return num1;
	}
	public void setNum1(int num1) {
		this.num1 = num1;
	}
	public int getNum2() {
		return num2;
	}
	public void setNum2(int num2) {
		this.num2 = num2;
	}
	public int add(){
		return (num1+num2);
	}
	public int subtraction(){
		return (num1-num2);
	}
	public int multi(){
		return (num1*num2);
	}
	public double division(){
		if(num2==0)
			return 0;
		return (num1/num2);
	}
	public int squre(){
		return (num1*num1);
	}
}
public class arithmetic {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
      Arith ari = new Arith(9,3);
      System.out.println(ari.add());
      System.out.println(ari.subtraction());
      System.out.println(ari.multi());
      System.out.println(ari.division());
      System.out.println(ari.squre());
	}

}

你可能感兴趣的:(简单四则运算)