/** A class that creates a histogram from data passed as arguments on the command line. */ public class Histogram { /** Contains the main method. @param args used for command-line arguments */ public static void main(String[] args) { int total; // The total number of values entered at the command line. int[] ranges = new int[10]; // Constructs an array of 10 integer numbers. int[] values = new int[args.length]; // Constructs an array of integer numbers (with the same length as the args array). // Parse each of the String objects and determine the integer values that were passed on the command line. for (int i = 0; i < args.length; i++) values[i] = Integer.parseInt(args[i]); // Determines how many values there are in each specified range. for (int i = 0; i < values.length; i++) { if (values[i] >= 1 && values[i] <= 10) ranges[0]++; if (values[i] >= 11 && values[i] <= 20) ranges[1]++; if (values[i] >= 21 && values[i] <= 30) ranges[2]++; if (values[i] >= 31 && values[i] <= 40) ranges[3]++; if (values[i] >= 41 && values[i] <= 50) ranges[4]++; if (values[i] >= 51 && values[i] <= 60) ranges[5]++; if (values[i] >= 61 && values[i] <= 70) ranges[6]++; if (values[i] >= 71 && values[i] <= 80) ranges[7]++; if (values[i] >= 81 && values[i] <= 90) ranges[8]++; if (values[i] >= 91 && values[i] <= 100) ranges[9]++; } // Prints to the screen a chart that prints an asterisk for each value entered that falls within a specified range. System.out.print("\n1 - 10 | "); for (int i = 0; i < ranges[0]; i++) System.out.print("*"); System.out.print("\n11 - 20 | "); for (int i = 0; i < ranges[1]; i++) System.out.print("*"); System.out.print("\n21 - 30 | "); for (int i = 0; i < ranges[2]; i++) System.out.print("*"); System.out.print("\n31 - 40 | "); for (int i = 0; i < ranges[3]; i++) System.out.print("*"); System.out.print("\n41 - 50 | "); for (int i = 0; i < ranges[4]; i++) System.out.print("*"); System.out.print("\n51 - 60 | "); for (int i = 0; i < ranges[5]; i++) System.out.print("*"); System.out.print("\n61 - 70 | "); for (int i = 0; i < ranges[6]; i++) System.out.print("*"); System.out.print("\n71 - 80 | "); for (int i = 0; i < ranges[7]; i++) System.out.print("*"); System.out.print("\n81 - 90 | "); for (int i = 0; i < ranges[8]; i++) System.out.print("*"); System.out.print("\n91 - 100 | "); for (int i = 0; i < ranges[9]; i++) System.out.print("*"); // Calculates the total number of values entered at the command line. total = ranges[0] + ranges[1] + ranges[2] + ranges[3] + ranges[4] + ranges[5] + ranges[6] + ranges[7] + ranges[8] + ranges[9]; // Prints to the screen the total number of values entered at the command line. System.out.println("\n\nThe total number of values entered at the command line was: " + total); } }