
Write a JAVA program to parse an array and print the greatest value and the number of occurrences of that value in the array. You can initialize the array random values in the program without the need to read them.

Hi Friend,
Try the following code:
import java.util.*;
class FindGreatest{
public static void main(String[] args)
{
int max = Integer.MIN_VALUE;
int count=0;
int arr[]=new int[5];
Random input=new Random();
for(int i=0;i<arr.length;i++){
arr[i]=input.nextInt(50);
}
System.out.println("Array Elements are: ");
for(int i=0;i<arr.length;i++){
System.out.println(arr[i]);
if (arr[i] > max) {
max = arr[i];
}
}
for(int i=0;i<arr.length;i++){
if(arr[i]==max){
count++;
}
}
System.out.println("Maximum Number is: "+max);
System.out.println("No of occurrences of greatest number: "+count);
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.