- public class A {
- public static void main(String[] args) {
- System.out.println("2 to the 5th power: "+MyMath.pow(2, 5));
- System.out.println("2 minus 5: "+MyMath.minus(2, 5));
- System.out.println("2 plus 5: "+MyMath.plus(2, 5));
- }
- }
- class MyMath
- {
- static int pow(int a, int b)
- {
- int res=1;
- for(int i=1; i<=b; i++)
- res*=a;
- return res;
- }
-
- static int minus(int a, int b)
- {
- return a-b;
- }
-
- static int plus(int a, int b)
- {
- return a+b;
- }
- }
複製代碼 |