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

I am having trouble solving this programming problem in BlueJ. The questions is

ID: 3686519 • Letter: I

Question

I am having trouble solving this programming problem in BlueJ. The questions is --- Write a Java class that contains an int array as a field. Initialize the array to the following list: 5, 10, 15, 20, 30, 40, 50, 35, 20, 5. Use the numbers in the array to create the following histogram using nested loops:

*****

**********

***************

********************

******************************

****************************************

**************************************************

***********************************

***************

*****

Thank you for your help with this. Remember it is in BlueJ.

Explanation / Answer

public class HIstogram {

   public static void main(String[] args) {
      
       //declaring and initializing array
       int []arr = {5, 10, 15, 20, 30, 40, 50, 35, 20, 5};
      
       // iterating over all elements of array
       for(int i=0; i<arr.length; i++){
          
           for(int j=1; j<=arr[i]; j++){ // for each element, print histogram
               System.out.print("*");
           }
           System.out.println();
       }
   }
}


/*

Output:

*****
**********
***************
********************
******************************
****************************************
**************************************************
***********************************
********************
*****

*/