日期:2014-05-20  浏览次数:20642 次

java acm的简单格式输入输出(刚接触求大神!!!),题实现连续输入多行并求每行之和
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
java acm

------解决方案--------------------

import java.util.Scanner;
import java.io.*;
public class Main{
public static void main(String []args){
//这种方式读取数据比较慢。像这题的要求是够了。如果数量超大可使用下面的方法
Scanner sc = new Scanner(System.in);
//下面的这种试读取速度比较快。
//Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
int a,b;
while(sc.hasNextInt()){
a=sc.nextInt();
b=sc.nextInt();
System.out.println(a+b);
}
}
}

像这个题每个OJ上都有示范源代码的呀。