我是編程新手。當我運行下面的代碼時,它只執行if語句並只打印「xmap」。但是我的輸入既包含'x'也包含'y',所以我希望我的程序能夠抓取每一行,並查看'x'或'y'並同時打印。誰能幫我這個。if else語句執行
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);
}
}
備註,公約明智,類應該開始與大寫。 '公共課Abc' – 2012-08-03 22:41:32
向我們顯示您的輸入文件。 – 2012-08-03 22:50:39