我是编程新手。当我运行下面的代码时,它只执行 if 语句并只打印“xmap”。但是我的输入有'x'和'y',所以我希望我的程序爬过每一行,看看是'x'还是'y'并打印两者。谁能帮我这个。
import java.io.*;
import java.util.*;
public class abc {
public static void main(String[] args) {
Map<String, List<String>> xMap = new HashMap<String, List<String>>();
Map<String, List<String>> yMap = new HashMap<String, List<String>>();
try {
Scanner scanner = new Scanner(new FileReader("C:/"));
while (scanner.hasNextLine()) {
String nextLine = scanner.nextLine();
String[] column = nextLine.split(":");
if (column[0].equals("x")) {
if (column.length == 4) {
xMap.put(column[1], Arrays.asList(column[2], column[3]));
} else {
yMap.put(column[1], Arrays.asList(column[2], column[3]));
}
}
}
scanner.close();
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println(xMap);
System.out.println(yMap);
}
}