- import java.util.Scanner;
- public class Ch01 {
- public static void main(String args[])
- {
- Scanner s=new Scanner(System.in);
- System.out.println("2加上5等於"+MyMath.plus(2, 5));
- System.out.println("2減去5等於"+MyMath.minus(2, 5));
- System.out.println("2的5次方為"+MyMath.pow(2, 5));
- }
- }
- class MyMath
- {
- static int pow(int x,int y){
- int a=1;
- for(int i=1;i<=y;i++)
- a*=x;
- return a;
- }
- static int minus(int x,int y){
- return x-y;
- }
- static int plus(int x,int y){
- return x+y;
- }
- }
複製代碼 |