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

TOP

返回列表