当前位置:   article > 正文

Java编程笔试中常用输入格式_java 笔试字符串输入

java 笔试字符串输入

每行输入带有空格的数字

示例输入

6
2 1
3 2
4 3
5 2
6 1
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
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<count;i++){
	    String temp = in.nextLine();
	    String[] ss = temp.trim().split(" ");
	    num[i][0] = Integer.parseInt(ss[0]);
	    num[i][1] = Integer.parseInt(ss[1]);
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

输入带有数字和字符串

示例输入

3
aa
b
ac
bbaac
  • 1
  • 2
  • 3
  • 4
  • 5
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<count;i++){
        strs[i] = in.nextLine();
    }
    String strT = in.nextLine();
    System.out.println(0);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

输入带有数字和符号

示例输入

20,3
  • 1
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]);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/227047
推荐阅读
相关标签
  

闽ICP备14008679号