【发布时间】:2019-12-02 22:55:33
【问题描述】:
class FindMinTester1 extends Vehiclehw {
Vehiclehw [] myVehicles = new Vehiclehw[100];
public static double findMin (Vehiclehw[] theVehicles) {
int min = 0;
for(int i = 1; i < Vehiclehw.length-1; i++) {
if(Vehiclehw[i].getprice() < min)
min = Vehiclehw[i].getprice;
}
return Vehiclehw;
}
}
// 所以我理解这个问题有点模糊,但基本上我有一个名为 Vehiclehw 的超类,它有一个价格,在这个类中,我试图在 100 个元素的数组中找到最低价格。我知道没有声明任何对象,但我或多或少只需要知道在给定问题的情况下我将如何编写此方法。我得到的只是前两行。任何指导将不胜感激。
【问题讨论】:
-
如果你从零开始
min,价格会比以往更低吗? -
int min = Vehiclehw[0].getprice();....return min;. -
@CoolMind 运行良好,直到
theVehicles为空,然后我们就有了 AIOOBE。 -
@ggorlen,是的。当我们讨论时,有人复制了我们的解决方案。 :)
-
@ArvindKumarAvinash,谢谢!我也看了你的简介,发现你很受欢迎。很高兴听到你的声音!