我必须搜索一个凯迪拉克对象数组,以显示某个模型的结果,比如说“Escalade”,并且我无法确定我的代码需要放在哪里为了在控制台屏幕上打印结果。当我尝试打印我现在拥有的内容时,我一直陷在循环中。关于我的程序的其他一切工作正常,我只需要能够在控制台屏幕上显示多个结果。循环搜索一个数组,打印多个结果
这里是我的代码:
while(response != null)
{
if(response.length() > 0)
{
count = 0;
found = false;
while(count < data.length && data[count] != null && !found)
{
item = data[count].getModel();
if(item.equalsIgnoreCase(response))
{
found = true;
}
else{
count++;
}
message = "Model: " + data[count].getModel() + "\n" +
"Stock Number: " + data[count].getStockNum() + "\n" +
"Color : " + data[count].getColor() + "\n" +
"Price : " + data[count].getPrice();
System.out.print(message);
}
if(!found)
message = "Model not found in array.";
}
}
response = JOptionPane.showInputDialog(prompt);
}
而且,搜索的第二部分是用来显示车是在用户的输入$ 3000的搜索结果,并肯定会升值对一些指导因为这两种类型的搜索相对相似。