Java编程笔试中常用输入格式

每行输入带有空格的数字

示例输入

6
2 1
3 2
4 3
5 2
6 1
public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	int count = Integer.parseInt(in.nextLine())-1;
	int[][] num = new int[count][2];
	for(int i=0;i

输入带有数字和字符串

示例输入

3
aa
b
ac
bbaac
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int count = in.nextInt();
    in.nextLine();
    String[] strs = new String[count];
    for(int i=0;i

输入带有数字和符号

示例输入

20,3
public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    String[] line = in.nextLine().split(",");
    int m = Integer.valueOf(line[0]);
    int k = Integer.valueOf(line[1]);
}

你可能感兴趣的:(Java算法与数据结构)