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

Colleen is turning n years old! She has n candles of various heights on her cake

ID: 3841516 • Letter: C

Question

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. 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. Print the number of candles Colleen blows out on a new line. 4 3 2 1 3 2 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

Java Program :-

import java.util.Scanner;

public class HelloWorld{

     public static void main(String []args){
       
        int n, max,count=0;

        Scanner s = new Scanner(System.in);

        System.out.println("Please Enter the 2 line input : ");
        System.out.println("<First Line for Number of Candels> ");
        System.out.println("<Second Line for thier respective heights> ");

        n = s.nextInt();

        int a[] = new int[n];

        for(int i = 0; i < n; i++)

        {

            a[i] = s.nextInt();

        }

        max = a[0];

        for(int i = 0; i < n; i++){

            if(max < a[i]){

                max = a[i];
            }

        }

        for(int i = 0; i < n; i++){
          
            if(a[i] == max) count++;
        }
      
        System.out.println("Number of candels colleen blows out is :");
        System.out.println(count);
    }
}


/*

      Output :-

     

Please Enter the 2 line input :                                                                                                                                          

<First Line for Number of Candels>                                                                                                                                       

<Second Line for thier respective heights>                                                                                                                                

4                                                                                                                                                                        

3 1 2 3                                                                                                                                                                  

Number of candels colleen blows out is :                                                                                                                                 

2

*/