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

问题描述
你的任务是计算a + b。
太容易了?!当然!我专门为acm初学者设计了这个问题。
您必须发现某些问题与此问题具有相同的标题,是的,所有这些问题都是针对相同的目标而设计的。

输入
输入将由一系列整数a和b组成,由空格分隔,每行一对整数。

产量
对于每对输入整数a和b,您应该在一行中输出a和b的总和,并在输入中输出每行的一行输出。

样本输入
1 5
10 20

样本输出
6
30

解析:本题主要是考虑到多组数据的输入,这里使用Scanner里的hasNext方法,从而实现多组数据输入。

import java.util.Scanner;

public class Main {
     

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

你可能感兴趣的:(Java例题与应用,Java——A+B,for,Input-Output,Practice)