//接口Compute
package jieKou;

public interface Compute {
int Computer(int n,int m);

}

//加
package jieKou;

public class Jia implements Compute {

@Override
public int Computer(int n, int m) {
	// TODO 自动生成的方法存根
	return m+n;
}

}

//减
package jieKou;

public class Jian implements Compute {

@Override
public int Computer(int n, int m) {
	// TODO 自动生成的方法存根
	return n-m;
}

}

//乘
package jieKou;

public class Cheng implements Compute {

@Override
public int Computer(int n, int m) {
	// TODO 自动生成的方法存根
	return n*m;
}

}

//除

package jieKou;

public class Chu implements Compute {

@Override
public int Computer(int n, int m) {
	// TODO 自动生成的方法存根
	return n/m;
}

}

//UseCompute

package jieKou;

public class UseCompute {
public void useCom(Compute com, int one, int two)
{
System.out.println(com.Computer(one, two));
}

}
//测试类

package jieKou;

public class Test001 {

public static void main(String[] args) {
	UseCompute a=new UseCompute();
	a.useCom(new Jia(), 5, 6);
	a.useCom(new Jian(), 5, 6);
	a.useCom(new Cheng(), 5, 6);
	a.useCom(new Chu(), 30, 6);
}

}

///运行结果

11
-1
30
5

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-11-07
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案