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

  2.         public static void main(String[] args) {
  3.                 System.out.println("2 to the 5th power: "+MyMath.pow(2, 5));
  4.                 System.out.println("2 minus 5: "+MyMath.minus(2, 5));
  5.                 System.out.println("2 plus 5: "+MyMath.plus(2, 5));
  6.         }
  7. }
  8. class MyMath
  9. {
  10.         static int pow(int a, int b)
  11.         {
  12.                 int res=1;
  13.                 for(int i=1; i<=b; i++)
  14.                         res*=a;
  15.                 return res;
  16.         }
  17.        
  18.         static int minus(int a, int b)
  19.         {
  20.                 return a-b;
  21.         }
  22.        
  23.         static int plus(int a, int b)
  24.         {
  25.                 return a+b;
  26.         }
  27. }
複製代碼

TOP

返回列表