返回列表 發帖
  1. public class A{
  2.     public static void main(String[] args) {
  3.             MyMath a=new MyMath(2,5);
  4.             a.pow();
  5.             a.minus();
  6.             a.plus();
  7.     }
  8. }
  9. class MyMath{
  10.         int x,y;
  11.         MyMath(int x,int y){
  12.                 this.x=x;
  13.                 this.y=y;
  14.         }
  15.         void pow(){
  16.                 int m=1;
  17.                 for(int i=0;i<y;i++){
  18.                         m*=x;
  19.                 }
  20.                 System.out.println(x+"的"+y+"次方等於"+m);
  21.         }
  22.         void minus(){
  23.                 int n;
  24.                 n=x-y;
  25.                 System.out.println(x+"減"+y+"等於"+n);
  26.         }
  27.         void plus(){
  28.                 int o;
  29.                 o=x+y;
  30.                 System.out.println(x+"加"+y+"等於"+o);
  31.         }
  32. }
複製代碼

TOP

返回列表