1089 A+B for Input-Output Practice (I)

小咪咪 2023-02-10 08:08 259阅读 0赞

1089 A+B for Input-Output Practice (I)

目录

Problem Description

Your task is to Calculate a + b.
Too easy?! Of course! I specially designed the problem for acm beginners.
You must have found that some problems have the same titles with this one, yes, all these problems were designed for the same aim.

Input

The input will consist of a series of pairs of integers a and b, separated by a space, one pair of integers per line.

Output

For each pair of input integers a and b you should output the sum of a and b in one line, and with one line of output for each line in input.

Sample Input

1 5
10 20

Sample Output

6
30

Author

lcy

Recommend

JGShining

Code

Problem1089.java

  1. import java.util.*;
  2. public class Problem1089 {
  3. public static void main(String[] args) {
  4. int a,b,sum,i;
  5. List<Integer> list = new ArrayList<>();
  6. Scanner reader=new Scanner(System.in);
  7. while(reader.hasNextInt()) {
  8. a=reader.nextInt();
  9. b=reader.nextInt();
  10. sum =a+b;
  11. list.add(sum);
  12. }
  13. Integer[] intArray = list.toArray(new Integer[list.size()]);
  14. for(i = 0;i<intArray.length;i++){
  15. System.out.println(intArray[i]);
  16. }
  17. }
  18. }

能力不足,实在无法写成题目所说的那样,只能由写入一个非int类型的值进行循环中断,望大神指教。

发表评论

表情:
评论列表 (有 0 条评论,259人围观)

还没有评论,来说两句吧...

相关阅读