...
1 public static void main(String[] args) { 2 Scanner sc = new Scanner(System.in); 3 System.out.println("請輸入數字給第一個加數賦值:"); 4 int num1 = 0; 5 try { 6 num1 = sc.nextInt(); 7 } catch (Exception ex) { 8 System.out.println("輸入的信息中出現數字以外的其他字元。"); 9 } 10 int num2 = 123; 11 System.out.println(num1 + "+" + num2 + "=" + (num1 + num2)); 12 13 }