妈妈对孩子成长的寄语:大家看一下这里是哪错了,编译没有报错,运行出错了

来源:百度文库 编辑:高校问答 时间:2024/05/02 11:43:39
import java.util.*;
class comparator implements Comparator{
public int compare(Object o1,Object o2){
String astr,bstr;
int i,j,k;
astr=(String) o1;
bstr=(String) o2;
i=astr.lastIndexOf(' ');
j=bstr.lastIndexOf(' ');
k=astr.substring(i).compareTo(bstr.substring(i));
if(k==0){
return astr.compareTo(bstr);
}
else{
return k;
}

}
}
class mytest{
public static void main(String[] args){
TreeMap tm=new TreeMap(new comparator());
tm.put("zhang", new Double(6446.32));
tm.put("lisi", new Double(5646.35));
tm.put("wangwu", new Double(5454.012));
tm.put("zhaoliu", new Double(544.210));
Set set =tm.entrySet();
Iterator it=set.iterator();
while(it.hasNext()){
Map.Entry me=(Map.Entry)it.next();
System.out.print(me.getKey()+":");
System.out.println(me.getValue());

}
System.out.println();
double bal=((Double)tm.get("zhang")).doubleValue();
tm.put("zhang",new Double(bal+100));
System.out.println("zhang 's new balance is:"+tm.get("zhang"));
}
}