输入:
输入包括两个正整数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
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 --;
}
}
}
输入:
输入包括两个正整数a,b(1 <= a, b <= 10^9),输入数据有多组, 如果输入为0 0则结束输入
输出:
输出a+b的结果
示例:
输入:
1 5
10 20
0 0
输出:
6
30
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)
}
}
}
输入:
输入数据包括多组。
每组数据一行,每行的第一个整数为整数的个数n(1 <= n <= 100), n为0的时候结束输入。
接下来n个正整数,即需要求和的每个正整数。
输出:
每组数据输出求和的结果
示例:
输入:
4 1 2 3 4
5 1 2 3 4 5
0
输出:
10
15
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
sum += sc.nextInt()
}
System.out.println(sum)
}
}
}
输入:
输入的第一行包括一个正整数t(1 <= t <= 100), 表示数据组数。
接下来t行, 每行一组数据。
每行的第一个整数为整数的个数n(1 <= n <= 100)。
接下来n个正整数, 即需要求和的每个正整数。。
输出:
每组数据输出求和的结果
示例:
输入:
2
4 1 2 3 4
5 1 2 3 4 5
输出:
10
15
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
sum += sc.nextInt()
}
System.out.println(sum)
}
}
}
输入:
输入数据有多组, 每行表示一组输入数据。
每行的第一个整数为整数的个数n(1 <= n <= 100)。
接下来n个正整数, 即需要求和的每个正整数。
输出:
每组数据输出求和的结果
示例:
输入:
4 1 2 3 4
5 1 2 3 4 5
输出:
10
15
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
sum += sc.nextInt()
}
System.out.println(sum)
}
}
}
输入:
输入数据有多组, 每行表示一组输入数据。
每行不定有n个整数,空格隔开。(1 <= n <= 100)
输出:
每组数据输出求和的结果
示例:
输入:
1 2 3
4 5
0 0 0 0 0
输出:
6
9
0
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
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();
}
}
}
输入:
多个测试用例,每个测试用例一行。
每行通过,隔开,有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[] strs = sc.nextLine().split(",")
Arrays.sort(strs)
for(int i = 0
System.out.print(strs[i])
if(i != strs.length - 1){
System.out.print(",")
}
}
System.out.println()
}
}
}
输入:
输入有多组测试用例,每组空格隔开两个整数
输出:
对于每组数据输出一行两个整数的和
示例:
输入:
1 1
输出:
2
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)
}
}
}