Okay, so I have the program complete but i cannot figure out how to get the second part.
It asks, "Print an asterisk for every five values in each category." My program right now prints an asterisk for every value.
This is my program so far:
It asks, "Print an asterisk for every five values in each category." My program right now prints an asterisk for every value.
This is my program so far:
Code:
//*****************************************************************
//Histogrm1.Java
//
//Java program that takes numerical inputs between 1-100 and prints
//them in to categories of 10 with a * to represent each 5 number
//values
//*****************************************************************
import java.io.*;
public class Histogram1 {
// Main method
public static void main(java.lang.String[] args) throws IOException {
//Storage of int
DataInputStream stdin = new DataInputStream (System.in);
final int MAXRANGE = 10;
final int MINRANGE = 1;
final int RANGE = 10;
int[] list = new int[MAXRANGE];
for (int i=0; i<list.length; i++) {
list[i] = 0;
}
// Enter Integers of range
System.out.println ("Enter some numbers between 1 and 100.");
System.out.println ("Signal the end by entering a number outside of that range.");
// Entering the actual number
System.out.print ("Enter Integer: ");
int value = Integer.parseInt (stdin.readLine());
// Will keep adding integers within range
while (value >= MINRANGE && value <= (MAXRANGE*RANGE)) {
// Range
list[(value-1)/RANGE] = list[(value-1)/RANGE] + 1;
// Enter next integer
System.out.print ("Enter Integer: ");
value = Integer.parseInt (stdin.readLine());
}
// Print histogram
System.out.println ("\nThis is the histogram:");
for (int i=0; i<list.length; i++) {
System.out.print (" " + (i*RANGE+1) + " - " + (i+1)*RANGE + "\t| ");
// Print *
for (int j=0 ; j<list[i] ; j++) {
System.out.print ("*");
}
System.out.println ();
}
}
}
Comment