public class Demo02ScannerSum { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("請輸入第一個數字:"); int a = sc.nextInt(); System.out.println("請輸入第二個數字:"); int b = sc.nextInt(); System.out.println("請輸入第三個數字:"); int c = sc.nextInt(); //首先得到前兩個最大值 int temp = a > b ? a : b; //再讓原來的最大值和第三個值對比 int temp2 = temp > c ? temp : c; System.out.println("最大值為"+temp2); } }