首页 > 技术文章 > [编程题] 牛客输入输出练习1-计算a+b(多组输入)

jiyongjia 2020-07-13 12:04 原文

牛客输入输出练习1-计算a+b(多组输入)

题目描述

计算多组输入的a+b

示例

输入输出描述:

输入描述:

输入包括两个正整数a,b(1 <= a, b <= 10^9),输入数据包括多组。

输出描述:

输出a+b的结果

例如2:

输入:

1 5
10 20

输出:

6
30

Java代码

import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        ArrayList<Integer> lis = new ArrayList<Integer>();
        while(scanner.hasNextLine()){
            String[] lines = scanner.nextLine().split(" ");
            int a = Integer.parseInt(lines[0]);
             int b = Integer.parseInt(lines[1]);
            lis.add(a+b);
        }
        //输出
        for(Integer i : lis){
            System.out.println(i);
        }
    }
    
    
}

输出

已AC

推荐阅读