输入:
输入包括两个正整数a,b(1 <= a, b <= 1000),输入数据包括多组。
输出:
输出a+b的结果
示例:
输入:
1 5
10 20
输出:
6
30
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
String[] s = sc.nextLine().split(" ");
int sum = 0;
for(int i = 0; i < s.length; i ++){
sum = sum + Integer.parseInt(s[i]);
}
System.out.println(sum);
}
}
}
输入:
输入第一行包括一个数据组数t(1 <= t <= 100)
接下来每行包括两个正整数a,b(1 <= a, b <= 1000)
输出:
输出a+b的结果
示例:
输入:
2
1 5
10 20
输出:
6
30
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
while(n > 0){
String[] s = br.readLine().split(" ");
int a = Integer.parseInt(s[0]);
int b = Integer.parseInt(s[1]);
System.out.println(a + b);
n --;
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int a = sc.nextInt();
int b = sc.nextInt();
if(a == 0 && b == 0){
break;
}
System.out.println(a + b);
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextInt()){
int n = sc.nextInt();
if(n == 0) break;
int sum = 0;
for(int i = 0; i < n; i++){
sum += sc.nextInt();
}
System.out.println(sum);
}
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(sc.hasNext()){
int n = sc.nextInt();
int sum = 0;
for(int i = 0; i < n; i++){
sum += sc.nextInt();
}
System.out.println(sum);
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
int sum = 0;
for(int i = 0; i < n; i++){
sum += sc.nextInt();
}
System.out.println(sum);
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNext()){
String s = in.nextLine();
String[] arr = s.split(" ");
int sum = 0;
for(String str: arr){
sum += Integer.parseInt(str);
}
System.out.println(sum);
}
}
}
输入:
输入有两行,第一行n
第二行是n个字符串,字符串之间用空格隔开
输出:
输出一行排序后的字符串,空格隔开,无结尾空格
示例:
输入:
5
c d a bb e
输出:
a bb c d e
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[] arr = new String[n];
int index = 0;
while(sc.hasNext()){
arr[index++] = sc.next();
}
Arrays.sort(arr);
for(int i = 0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
}
}
输入:
多个测试用例,每个测试用例一行。
每行通过空格隔开,有n个字符,n<100
输出:
对于每组测试用例,输出一行排序过的字符串,每个字符串通过空格隔开
示例:
输入:
a c bb
f dddd
nowcoder
输出:
a bb c
dddd f
nowcoder
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine()){
String[] arr = sc.nextLine().split(" ");
Arrays.sort(arr);
for(String s: arr){
System.out.print(s + " ");
}
System.out.println();
}
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String s = sc.nextLine();
String[] str = s.split(" ");
Long a = Long.valueOf(str[0]);
Long b = Long.valueOf(str[1]);
System.out.println(a + b);
}
}
}