- import java.lang.System;
- import java.util.Scanner;
- public class ch75
- {
- public static void main(String args[])
- {
- int x,y;
- MyMath m=new MyMath();
- Scanner s=new Scanner(System.in);
- System.out.print("請輸入第一個數: ");
- x=s.nextInt;
- System.out.print("請輸入第二個數: ");
- y=s.nextInt;
- System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y));
- System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
- System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
- }
- }
- class MyMath
- {
- public static float pow(int a,int b)
- {
- int result=1;
- for(int i=0; i<=b; i++)
- result=result*a;
- return result;
- }
- public static int minus(int a,int b)
- {
- return a-b;
- }
- public static int plus(int a,int b)
- {
- return a+b;
- }
- }
複製代碼 |