- import java.io.Console;
- public class ch18
- {
- public static void main(String args[])
- {
- int a, b, c, d, pigger ;
- int ab, cd;
- Console keyin=System.console();
- System.out.println("四數中找出較大的數 ");
- System.out.println("請輸入第一數 : ");
- a = Integer.parseInt(keyin.readLine());
- System.out.println("請輸入第二數 : ");
- b = Integer.parseInt(keyin.readLine());
- System.out.println("請輸入第三數 : ");
- c = Integer.parseInt(keyin.readLine());
- System.out.println("請輸入第四數 : ");
- d = Integer.parseInt(keyin.readLine());
-
- ab=(a>b)?a:b;
- cd=(c>d)?c:d;
- pigger=(ab>cd)?ab:cd;
- System.out.println("最大數為"+ pigger);
- }
- }
複製代碼 |