我有以下代码
public static void main(String args[]){
Scanner scanner = new Scanner(System.in);
int noOfTestCases = scanner.nextInt();
String[] firstStringsList = new String[noOfTestCases];
String[] secondStringsList = new String[noOfTestCases];
for(int i=0;i<noOfTestCases;i++){
firstStringsList[i] = scanner.nextLine();
secondStringsList[i] = scanner.nextLine();
}
for(int i=0;i<noOfTestCases;i++){
System.out.println("First String : " + firstStringsList[i]);
System.out.println("Second String : " + secondStringsList[i]);
}
}
,输出为
1
asd
First String :
Second String : asd
即我先输入1表示我有1个测试用例涉及获取two String inputs(per test case).
但是我只能输入1个分配给secondStringsList[i]
的字符串。我正在使用Intellij IDEA
。为什么会这样?解决办法:
答案 0 :(得分:0)
我可能已修复您的问题
public static void main(String args[]) {
Scanner scanner = new Scanner(System.in);
int noOfTestCases = scanner.nextInt();
String[] firstStringsList = new String[noOfTestCases];
String[] secondStringsList = new String[noOfTestCases];
scanner.nextLine();
for (int i = 0; i < noOfTestCases; i++) {
firstStringsList[i] = scanner.nextLine();
secondStringsList[i] = scanner.nextLine();
}
for (int i = 0; i < noOfTestCases; i++) {
System.out.println("First String : " + firstStringsList[i]);
System.out.println("Second String : " + secondStringsList[i]);
}
}