public static void main(String[] args) throws IOException {
HashMap<String,Integer> map = new HashMap<String, Integer>();
map.put("自行车", 10);
map.put("两座车", 8);
map.put("四座车", 2);
Scanner sc = new Scanner(System.in);
System.out.println(map);
BufferedWriter bw = new BufferedWriter(new FileWriter("xxx.txt"));
while(true) {
String str = sc.nextLine();
if("quit".equals(str))
break;
bw.write(str);
bw.newLine();
String s = map.get(str) == null ? "" : map.get(str) + "";
System.out.println(s);
bw.write(s);
bw.newLine();
}
bw.close(); |
|