返回列表 發帖
本帖最後由 張啟廣 於 2019-7-2 16:00 編輯
  1. import java.util.Scanner;


  2. public class Ch03
  3. {

  4.         public static void main(String[] args)
  5.         {
  6.              int a, b, c, d, e, f, g;       
  7.          Scanner s=new Scanner(System.in);
  8.          System.out.print("請依序輸入四個數: ");
  9.          a=s.nextInt();
  10.          b=s.nextInt();
  11.          c=s.nextInt();
  12.          d=s.nextInt();
  13.          if(a>b)
  14.                 e=a;
  15.         else
  16.                 e=b;
  17.          if(c>d)
  18.                  f=c;
  19.          else
  20.                  f=d;
  21.          if(e>f)
  22.                  g=e;
  23.          else
  24.                  g=f;
  25.          System.out.println("最大數為: "+g);
  26.         }

  27. }
複製代碼
  1. import java.util.Scanner;


  2. public class Ch03
  3. {

  4.         public static void main(String[] args)
  5.         {
  6.              int a, b, c, d, e, f, g;       
  7.          Scanner s=new Scanner(System.in);
  8.          System.out.print("請依序輸入四個數: ");
  9.          a=s.nextInt();
  10.          b=s.nextInt();
  11.          c=s.nextInt();
  12.          d=s.nextInt();
  13.          e=a>b?a:b;
  14.          f=c>d?c:d;
  15.          g=e>f?e:f;
  16.          System.out.println("最大數為: "+g);
  17.         }

  18. }
複製代碼

TOP

返回列表