- import java.io.Console;
- public class ch17
- {
- public static void main (String args[])
- {
- int a, b, c, d, max;
- Console console=System.console();
- System.out.print("請輸入第1個數: ");
- a=Integer.parseInt(console.readLine());
- max = a;
- System.out.print("請輸入第2個數: ");
- b=Integer.parseInt(console.readLine());
- max = (b>max?b:max);
- System.out.print("請輸入第3個數: ");
- c=Integer.parseInt(console.readLine());
- max = (c>max?c:max);
- System.out.print("請輸入第4個數: ");
- d=Integer.parseInt(console.readLine());
- max = (d>max?d:max);
- System.out.print("4數中較大的數為: " + max);
- }
- }
複製代碼 |