scanner.nextLine(); 读入空格
while(sc.hasNextLine()) 读每一行,行内读入空格,行内数据长度未知
String [] s=sc.nextLine().split(" "); 去掉空格
while(sc.hasNext()) 读每一行,行内不读空格
String为空 要输出 []
·计算两数之和
1.
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(a+b);
}
}
}
2.最开始输入组数
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int lineNumber = s.nextInt();
for (int i = 0; i < lineNumber; i++) {
int a = s.nextInt();
int b = s.nextInt();
System.out.println(a + b);
}
}
}
3.以0 0为结尾