Stay hungry. Stay foolish.

0%

Java题解注意事项

Java解题(ACM模式)注意事项

处理样例的循环输入输出

1
2
3
4
5
6
7
8
9
10
11
12
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
//注意while处理多个case
int a = input.nextInt();
int b = input.nextInt();
System.out.println(a + b);
}
}
}
1
2
3
4
5
6
7
8
9
10
11
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int line = input.nextInt();
scanner.nextLine();
for (int i = 0; i < line; i++) {
//code
}
}
}

常用函数