Question 2711
Multiple choice
Unit 4: Data Collections
Using the
Product class and the same file as the previous question. How many products have a price less than 4.0?
// (list built as in previous question: Milk 2.5, Bread 3.0, Eggs 4.5)
int count = 0;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getPrice() < 4.0) {
count++;
}
}
System.out.println(count);
Pick an answer, then check it. The solution opens in a window.
DCorrect answer
Answer images

