返回列表 發帖
  1. import java.lang.System;
  2. import java.util.Scanner;
  3. public class ch75
  4. {
  5.      public static void main(String args[])
  6.      {
  7.          int x,y;
  8.          MyMath m=new MyMath();
  9.          Scanner s=new Scanner(System.in);
  10.          System.out.print("請輸入第一個數: ");
  11.          x=s.nextInt;
  12.          System.out.print("請輸入第二個數: ");
  13.          y=s.nextInt;
  14.          System.out.println(x+"的"+y+"次方為"+MyMath.pow(x,y));
  15.          System.out.println(x+"減去"+y+"等於"+MyMath.minus(x,y));
  16.          System.out.println(x+"加上"+y+"等於"+MyMath.plus(x,y));
  17.      }
  18. }
  19. class MyMath
  20. {
  21.      public static float pow(int a,int b)
  22.      {
  23.         int result=1;
  24.         for(int i=0; i<=b; i++)
  25.            result=result*a;
  26.         return result;
  27.      }
  28.      public static int minus(int a,int b)
  29.      {
  30.         return a-b;
  31.      }
  32.      public static int plus(int a,int b)
  33.      {
  34.         return a+b;
  35.      }
  36. }
複製代碼

TOP

返回列表