本帖最後由 張啟廣 於 2019-7-2 16:00 編輯
- import java.util.Scanner;
- public class Ch03
- {
- public static void main(String[] args)
- {
- int a, b, c, d, e, f, g;
- Scanner s=new Scanner(System.in);
- System.out.print("請依序輸入四個數: ");
- a=s.nextInt();
- b=s.nextInt();
- c=s.nextInt();
- d=s.nextInt();
- if(a>b)
- e=a;
- else
- e=b;
- if(c>d)
- f=c;
- else
- f=d;
- if(e>f)
- g=e;
- else
- g=f;
- System.out.println("最大數為: "+g);
- }
- }
複製代碼- import java.util.Scanner;
- public class Ch03
- {
- public static void main(String[] args)
- {
- int a, b, c, d, e, f, g;
- Scanner s=new Scanner(System.in);
- System.out.print("請依序輸入四個數: ");
- a=s.nextInt();
- b=s.nextInt();
- c=s.nextInt();
- d=s.nextInt();
- e=a>b?a:b;
- f=c>d?c:d;
- g=e>f?e:f;
- System.out.println("最大數為: "+g);
- }
- }
複製代碼 |