Description: This program prints the following pattern(Horizontal Histogram):
if the array is of elements -|3|7|2|5|
***
*******
**
*****
according to the values entered in the array
*******
**
*****
according to the values entered in the array
Primary Inputs: Read 10 digits from the user
Primary Output: The pattern specified above
Platform Used: JDK 1.6 with JCreator
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
/*Read 10 digit value and display horizontal histogram |3|7|2|5| Histogram *** ******* ** ***** */ import java.io.*; //For Console class. class HHistogram { public static void main(String args[]) { Console con = System.console(); // For reading input from the console. // Will work with JDK 1.6 only int num; int[] arr = new int[10]; System.out.println("Enter 10 values"); for (int i = 0; i < arr.length; i++) { num = Integer.parseInt(con.readLine()); arr[i] = num % 10; } for (int i = 0; i < arr.length; i++) { for (int j = 0; j < arr[i]; j++) { System.out.print("* "); } System.out.println(); } } // end of main } |