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.
![5.
9 import java.util.Scanner;
11 public class MaxValue {
public static void main(String[] args) {
13
int count =
14
int number = -1;
|-1;
15
int max = -1;
16
17
18
Scanner input = new Scanner(System. in);
System.out.print("Enter numbers :");
22
while (number !-0) {
number =
input.nextInt();
24
if (number > max) {
25.
26.
27.
28
number;
count = 1;
%3!
29.
30,
3.
34.
else if (number ==
count++;
} (xx
System.out.println("The largest number is:
System.out.println("The occurrence count of the largest number is "+count);
+max);
Console X3
Problems J Debug Shell
<terminated> MaxValue [Java Application] C:\Program Files\Java\jdk-11.0.12\bin\javaw.exe (Oct 23, 2021, 8:39:16 PM - 8:39:24 PM)
Enter numbers : 5 55 0
The largest number is: 5
The occurrence count of the largest number is 3
直。
55°F
12
144
prt sc
delete
80](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe422c9ea-8878-485a-ab7d-9a867b7ec566%2Fb1317f06-8811-479a-a575-6304dbbf7886%2Fjdt7n8k.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
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
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)