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 }