本帖最後由 晏有聰 於 2012-10-8 20:26 編輯
- /* 比大小的sample */
- import java.io.Console;
- public class ch18
- {
- public static void main (String showdemo[])
- {
-
- int a,b,c,d,temp1,temp2,bigger;
- Console console=System.console();
- System.out.print("請輸入第1個數");
- a=Integer.parseInt(console.readLine());
- System.out.print("請輸入第2個數");
- b=Integer.parseInt(console.readLine());
- System.out.print("請輸入第3個數");
- c=Integer.parseInt(console.readLine());
-
- System.out.print("請輸入第4個數");
- d=Integer.parseInt(console.readLine());
-
- temp1=(a>b)?a:b;
- temp2=(c>d)?c:d;
- bigger=(temp1>temp2)?temp1:temp2;
- System.out.print("四數中較大數字="+bigger);
- }
- }
複製代碼 |