对输入的若干行(每行以空格或者多个空格)数字字符串求和并输出。
输入格式:
每行包含两个数字字符串,中间以一个或者多个空格分隔。
输出格式:
输出两个数的和
输入样例:
1 1
2 3
-100 100
-100 -100
10 0
输出样例:
在这里给出相应的输出。例如:
2 5 0 -200 10
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int a = sc.nextInt();
int b= sc.nextInt();
System.out.println(Math.addExact(a,b));
}
}
}
-
-
static int addExact(int x, int y) 返回其参数的总和,如果结果溢出 int ,则抛出异常。
static long addExact(long x, long y) 返回其参数的总和,如果结果溢出一个 long ,则抛出异常。
-



