在终端输入2个数字,然后根据输入的数字求和

2.实现代码

package cn.test.logan;

import java.util.Scanner;

public class Test02 {
    public static void main(String[] args) {
        // 首先,创建一个用于获取终端的输入的工具
        Scanner sc= new Scanner(System.in);
        
        // 获取用户输入的第一个数字
        String num1 = sc.nextLine();
        
        // 获取第二个数字
        String num2 = sc.nextLine();
        
        // 字符串转整型
        int number1 = Integer.parseInt(num1);
        int number2 = Integer.parseInt(num2);
        
        // 将两个数字相加得到和
        int res = number1 + number2;
        // 打印结果(快捷键:sout+alt+/)
        System.out.println(res);
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-20
  • 2021-12-25
  • 2022-12-23
  • 2021-09-23
  • 2022-01-21
  • 2021-07-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-12
  • 2022-12-23
  • 2021-10-09
  • 2021-08-13
  • 2021-11-06
相关资源
相似解决方案