返回列表 發帖
  1. public class Ch {

  2.         public static void main(String[] args) {
  3.                 // TODO 自動產生的方法 Stub
  4.                 MyMath a=new MyMath(2,5);
  5.                 a.pow();
  6.                 a.minus();
  7.                 a.plus();
  8.         }

  9. }
  10. class MyMath
  11. {
  12.         int x,y;
  13.         MyMath(int x,int y){
  14.                 this.x=x;
  15.                 this.y=y;
  16.         }
  17.         void pow(){
  18.                 int m=1;
  19.                  for(int i=0;i<y;i++){
  20.                         m*=x;
  21.                 }
  22.                 System.out.println(x+"的"+"次方等於"+m);
  23.         }
  24.         void minus(){
  25.                 int n;
  26.                 n=x-y;
  27.                 System.out.println(x+"減"+y+"等於"+n);
  28.         }
  29.         void plus()
  30.         {
  31.                 int o;
  32.                 o=x+y;
  33.                 System.out.println(x+"加"+y+"等於"+o);

  34.         }
  35. }
複製代碼

TOP

返回列表