0
2nd max number
How to find second maximum number in array using only one for loop in java?
3 ответов
+ 3
Are there possibly duplicate values in the array?
Here some ideas how it could be approached:
* Sort the array (ascending) and then take the 2nd last
* find the max, create a new array without max and get the max of the new array
* loop through the array and check if the current value is larger than any previous one and smaller than the max
+ 2
Martin Taylor yes, I wondered whether there could be duplicate values... I guess it depends on the teacher's intention with the task :)
+ 1
Martin Taylor, Lisa
Maybe something like this?
Only one loop and no sort:
https://code.sololearn.com/cvLEzLgWYrC2/?ref=app