in Java specifically I dont know string to int to cmopare ea

in Java

specifically, I don\'t know string to int[] to cmopare each numbers ....

Write a program that reads integers, finds the largest of them, and counts its occurrences. Assume that the input ends with number 0. Suppose that you entered 3 5 2 5 5 5 0; the program finds that the largest is 5 and the occurrence count for 5 is Enter numbers: 3 5 2 5 5 5 0 The largest number is 5 The occurrence count of the largest number is 4

Solution

MaxTest .java

import java.util.Scanner;


public class MaxTest {

   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       int max = 0, count = 0;
       System.out.println(\"Enter numbers: \");
      
       while(true){
           int n = scan.nextInt();
           if(n == 0){
               break;
           }
           else{
               if(max == n){
                   count++;
               }
               else if(max < n){
                   count = 1;
                   max = n;
               }
           }
       }
       System.out.println(\"The Largest number is \"+max);
       System.out.println(\"The occurance count of the largest number is \"+count);
   }

}

Output:

Enter numbers:
3 5 2 5 5 5 0
The Largest number is 5
The occurance count of the largest number is 4

in Java specifically, I don\'t know string to int[] to cmopare each numbers .... Write a program that reads integers, finds the largest of them, and counts its

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site