1.写了一段代码,但是为啥输不出内容呢?
2.import java.util.HashMap;
public class House {
private String name;
private HashMap<String,House> has=new HashMap<String,House>();
public House(String name){
this.name=name;
}
public void setExit(String dir,House house){
has.put(dir,house);
}
public String getExitDes(){
StringBuffer buffer=new StringBuffer(); for(String s:has.keySet()){ buffer.append(s); buffer.append(has.get(s)); } return buffer.toString();
}
public static void main(String[] args){
House house=new House("卧室"); House house1=new House("厨房"); House house2=new House("客厅"); house.setExit("left", house1); house.setExit("right", house2); System.out.print(house.getExitDes());
}
}
3.运行后,输出:
leftTest.House@2a139a55rightTest.House@15db9742没有输出房间的信息??
富国沪深
相关分类