[A+B Problem](单组数据输入)(http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Contest/contestproblem/cid/2575/pid/1000)
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int a,b;
a=input.nextInt();
b=input.nextInt();
System.out.println(a+b);
input.close();//关闭输入的流,释放内存。
}
}
A+B for Input-Output Practice (I)(多组数据输入)
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input=new Scanner(System.in);
int a,b;
while(input.hasNextInt()) {
a=input.nextInt();
b=input.nextInt();
System.out.println(a+b);
}
}
}
A+B for Input-Output Practice (II)(固定组数输入)
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int a, b, n;
n = input.nextInt();
do {
a = input.nextInt();
b = input.nextInt();
System.out.println(a + b);
} while (--n > 0);
}
}
A+B for Input-Output Practice (IV)(多组输入,如果输入第一个数为0,则结束)
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int a, b, i;
while (input.hasNextInt()) {
int sum = 0;
int n = input.nextInt();
if (n == 0)
break;//******
else {
for (i = 1; i <= n; i++) {
a = input.nextInt();
sum += a;
}
System.out.println(sum);
}
}
}
}