其他分享
首页 > 其他分享> > A+B 输入输出练习I

A+B 输入输出练习I

作者:互联网

题目描述

你的任务是计算a+b。

输入

输入包含一系列的a和b对,通过空格隔开。一对a和b占一行。

输出

对于输入的每对a和b,你需要依次输出a、b的和。

如对于输入中的第二对a和b,在输出中它们的和应该也在第二行。

样例输入

1 5
10 20

样例输出

6
30

思路:

通过hasNext()while循环可以实现一直进行输入,用两个变量接收输入的值,然后输出和。

代码:

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()){
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(a + b);
        }
    }
}

标签:输出,练习,hasNext,int,输入输出,System,public,输入
来源: https://blog.csdn.net/voilde/article/details/122608697