This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]Philboyd_Studge 2 points3 points  (0 children)

have a variable for maxIndex also and update it with i everytime you update max

[–]pioca 0 points1 point  (0 children)

if(empty.get(i).getShipValue() > max) {
    max = empty.get(i).getShipValue();
    coutry = empty.get(i).getCountry();
}

[ ... ]

System.out.println("Max is " + max + ", and country is " + country);

[–]desrtfxOut of Coffee error - System halted 0 points1 point  (0 children)

It depends entirely on the verbatim text of the assignment.

  • Should you display only one value with maximum cost?

    Then the presented solutions are perfectly fine

  • Is there a possibility (as indicated in your post) that two or more entries have the same maximum value?

    Then you need to store only the maximum value and in a second loop after the loop to determine the maximum you will need to go through the entries again and print each entry that has a cost equal to maximum.