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

  2.         public static void main(String[] args) {
  3.                 System.out.println("2的5次方為"+MyMath.pow(2, 5));
  4.                 System.out.println("2減去5等於"+MyMath.minus(2, 5));
  5.                 System.out.println("2加上5等於"+MyMath.plus(2, 5));
  6.         }

  7. }

  8. class MyMath
  9. {
  10.         static int pow(int x, int y)
  11.         {
  12.                 int res=1;
  13.                 for(int i=1; i<=y; i++)
  14.                     res*=x;
  15.                 return res;
  16.         }
  17.       
  18.         static int minus(int x, int y)
  19.         {
  20.                 return x-y;
  21.         }
  22.       
  23.         static int plus(int x, int y)
  24.         {
  25.                 return x+y;
  26.         }
  27. }
複製代碼

TOP

返回列表