Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

pls write the codes as simple as possible. Thank you. java Colleen is turning n

ID: 3841498 • Letter: P

Question

pls write the codes as simple as possible.

Thank you.

java

Colleen is turning n years old! She has n candles of various heights on her cake, and candle i has height height_i. Because the taller candles tower over the shorter ones, Colleen can only blow out the tallest candles. Given the height_i for each individual candle, find and print the number of candles she can successfully blow out. Input Format The first line contains a single integer, n, denoting the number of candles on the cake. The second line contains n space-separated integers, where each integer i describes the height of candle i. Output Format Print the number of candles Colleen blows out on a new line. Sample Input 4 3 2 1 3 Sample Output 2 Explanation We have one candle of height 1, one candle of height 2, and two candles of height 3. Colleen only blows out the tallest candles, meaning the candles where height = 3. Because there are 2 such candles, we print 2 on a new line.

Explanation / Answer

Hi,

Please find below the code-

Java code-

public class CountMax {
public static void main(String [] args) {
//Create scanner object
int n
Scanner input = new Scanner(System.in);

//Obtain user input
System.out.println("Enter number of candles ");
n=input.nextInt();

System.out.println("Enter the heights of candle separated by space ");
String[] array = input.nextLine().split(" ");

//Loop through array
int max = Integer.parseInt(array[0]);
int count = 0;
for (int i = 0; i < array.length; i++) {
if(Integer.parseInt(array[i]) > max) {
max = Integer.parseInt(array[i]);
} else if(Integer.parseInt(array[i]) == max) {
count++;
}
}
//Output
System.out.println("The largest number is " + max);
System.out.println("The occurrence count of the largest number is " + count);
}
}