- // 這是一個簡單的Java應用程式範例
- import java.io.*;//for 鍵盤輸入
- import java.lang.Math;
- import java.util.ArrayList;
- public class Hello
- {
- public static void main(String args[])throws IOException
- {
- printHW(); //呼叫printHW()方法
-
- //int powrt = pow2(5);
- System.out.println(pow2(5));
-
- int powab = pow3(5,3);
- System.out.println(powab);
-
- System.out.println(add(2,3));
-
- System.out.println(max(6,11));
-
- }
-
- //印出Hello world方法
- public static void printHW()
- {
- System.out.println("Hello World");
- }
-
- public static int pow2(int a)
- {
- return a*a;
- }
- public static int pow3(int a,int b)
- {
- int returnvalue = 1;
- for(int i=1; i<=b;i++)
- {
- returnvalue = returnvalue *a;
- }
- return returnvalue;
- }
-
- public static int add(int a,int b)
- {
- return a+b;
- }
-
- public static int max(int a,int b)
- {
- /*if(a>b)
- {
- return a;
- }
- else
- {
- return b;
- }*/
- return (a>b)?a:b;
-
- }
- }
複製代碼 |