Hi everyone, I am trying figure out is there a "more proper" way to show the multiple lowest values in an array. My array has 2 of the values that are lowest among the 8 values. I would like to know is there a way to show both of them without using:
for (int i = 0; i < price.length; ++i)
{
if (price[i]<= lowest)
{
lowest = price[i];
loworderNo=i;//make the lowest price order number equals to the i //value, who is index contains lowest price
}
}
System.out.println("Most Economical Food:\t" + (loworderNo-1) +"\t\t"+ item[loworderNo-1] + "\t" + lowest);
System.out.println("Most Economical Food:\t" + loworderNo +"\t\t"+ item[loworderNo] + "\t" + lowest);
Notes: My assignment is about a restaurant order taking software written in java to take order, etc and here is the actual array of the dishes & its price.
String[] itemArray = { "Premium Bento", "Deluxe Bento", "Salmon Teriyaki", "Tempura Ramen","Salmon Sashimi", "Maguro Sashimi", "Maguro Sushi", "Tamago Sushi" };
double[] priceArray = { 21.00, 17.00, 12.00, 10.00, 4.90, 4.90, 1.80, 1.80 };
See there is 2 lowest values, 2 of them are $1.80, I could have used the above method, but I just cannot satisfied with it (I think this is call hard coding right??)
Please help. Thank you.