public class BaiduZhiDao {
//未做异常处理,价格要输数字.
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
Ware[] wares = new Ware[10];
for (int i=0;i<10;i++){
Ware ware = new Ware();
System.out.println("请输入第"+(i+1)+"个产品信息:");
System.out.print("名称: ");
ware.setName(scanner.nextLine());
System.out.print("单价: ");
ware.setPrice(Double.valueOf(scanner.nextLine()));
wares[i]=ware;
}
Ware maxWare = getMaxPrice(wares);
System.out.println("单价最高,产品:"+maxWare.getName()+"--"+maxWare.getPrice());
}
static Ware getMaxPrice( Ware[] wares){
Ware maxWare = wares[0];
for (int i=1;iif(null!=wares[i] && wares[i].getPrice()>maxWare.getPrice()){
maxWare=wares[i];
}
}
return maxWare;
}
static class Ware{
String name ;
double price;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
}
}
用数据库排序功能就可以。