The picture is as far as i've gotten Sample 1: Enter numbers: 3 5 2 5 5 5 0 -------> user enters each number one at a time. Hits enter after each number. Puts 0 when user wants to end. The largest number is 5 The occurrence count of the largest number is 4
The picture is as far as i've gotten
Sample 1:
Enter numbers: 3 5 2 5 5 5 0 -------> user enters each number one at a time. Hits enter after each number. Puts 0 when user wants to end.
The largest number is 5
The occurrence count of the largest number is 4
The finishing touch is the part in bold but i cant find a solution.
Here I have created a list to store the numbers.
Next, I have used an infinite loop.
Inside the loop, I have taken input from the user and then used the if statement to check whether the input is 0 or not, if the input is 0 then I have stopped the loop using break otherwise I have added the input to the list.
Next, I have used stream API to get the max value from the list.
Then, I have iterated over the elements of the list and counted the number of elements equal to max.
In the end, I have printed the result to the console.
Step by step
Solved in 2 steps with 1 images