返回列表 發帖

四數中找出最大的數

本帖最後由 tonyh 於 2012-10-8 20:33 編輯
  1. import java.io.Console;
  2. public class ch18
  3. {
  4.   public static void main (String args[])
  5.   {
  6.       int a, b, c, d, e, f, g;
  7.       Console console=System.console();
  8.       System.out.print("請輸入第1個數: ");
  9.       a=Integer.parseInt(console.readLine());
  10.       System.out.print("請輸入第2個數: ");
  11.       b=Integer.parseInt(console.readLine());
  12.       System.out.print("請輸入第3個數: ");
  13.       c=Integer.parseInt(console.readLine());
  14.       System.out.print("請輸入第4個數: ");
  15.       d=Integer.parseInt(console.readLine());
  16.       e=(a>b)?a:b;
  17.       f=(c>d)?c:d;
  18.       g=(e>f)?e:f;
  19.       System.out.print("四數中最大的數為: "+g);
  20.   }
  21. }
複製代碼

返回列表