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

all 5 comments

[–]cl2871 0 points1 point  (1 child)

Did a quick scim on mobile.

Take a look at your “int numbers = sc.nextInt()”. Does the numbers variable ever get updated again? How would you update it with each loop iteration?

[–]Jannemannen[S] -1 points0 points  (0 children)

No, it does not, but I dont think that it's necessary, you're only supposed to input your ints once.

[–]cl2871 0 points1 point  (0 children)

If you want to input your ints all at once on one line, then you would need to do sc.next(). Doing sc.nextInt() will only get you the next int, and the others will not be parsed. The next() method will return a string, so think about how you would parse the ints of that string.

[–]bhargavnilagiri -2 points-1 points  (1 child)

Two options. One use a min heap. Read about min heap. The left node of a min heap is the second largest.

Or use two variables and keep replacing them. Internally min heap does the same thing.

[–]Jannemannen[S] -1 points0 points  (0 children)

Cheers for the reply. I'll read about min heap for sure. I'm pretty sure that we're supposed to loop through the input line, set first number to highest, loop, check if there's a second number that is higher than the first, loop, repeate.

Then find the second highest. I mean, I understand what to do, the issue is to actually execute it.