回覆列表
  • 1 # 山西維信科技

    interface Compute{

    public int compute(int n,int m);

    }

    class Add implements Compute{

    @Override

    public int compute(int num1, int num2) {

    return num1+num2;

    }

    }

    class Subtract implements Compute{

    @Override

    public int compute(int num1, int num2) {

    return num1-num2;

    }

    }

    class Multiply implements Compute{

    @Override

    public int compute(int num1, int num2) {

    return num1*num2;

    }

    }

    class Divide implements Compute{

    @Override

    public int compute(int num1, int num2) {

    return num1/num2;

    }}

    class UseCompute{

    public void useCom(Compute com, int one, int two){

    System.out.println(com.compute(one,two));

    }

    }

    public class Test{

    public static void main(String args[]){

    UseCompute u=new UseCompute();

    Add a=new Add();

    Divide d=new Divide();

    Multiply m=new Multiply();

    Subtract s=new Subtract();

    System.out.print("35+7=");

    u.useCom(a, 35, 7);

    System.out.print("35/7=");

    u.useCom(d, 35, 7);

    System.out.print("35*7=");

    u.useCom(m, 35, 7);

    System.out.print("35-7=");

    u.useCom(s, 35, 7);

    }

    }

  • 中秋節和大豐收的關聯?
  • 端午節快到了,你知道粽子有多少種包法嗎?包的材料一樣嗎?