问题详情

class ABC { String name; double price; public ABC(String na, double pr) {name=na; price=pr;} public int compareTo(ABC x) { if(name.compareTo(x.name)>0) return 1; if(name.compareTo(x.name)<0) return -1; else return 0; } } public class XXK5 { public static void main(String[] args) { String []s={"apple", "pear", "tangerme", "banana", "grape"}; double []d={3.8, 2.5, 3.2, 4.3, 5.2}; ABC []ar=new ABC[s.length]; int i,k=0; for(i=0; i<ar.length; i++) ar[i]=new ABC(s[i],d[i]); for(i=1; i<ar.length; i++) if(ar[i].compareTo(ar[k])>0) k=i; System.out.println(ar[k].name+" "+ar[k].price); } }


、<span>tangerme 3.2</span>

、<span>tangerme 4.8</span>

时间:2021-07-17 19:36 关键词:

答案解析

<span>tangerme 3.2</span>