Histogram Java, need help completing it

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amanjot24
    New Member
    • Oct 2012
    • 1

    Histogram Java, need help completing it

    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:

    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 ();  
          }
       }
    }
    Last edited by zmbd; Oct 4 '12, 09:32 PM. Reason: When posting HTML/VBA/JAVA/XML or simular, please use the <CODE/> format button
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    This reads very much like a homework question...
    Benefit of the doubt?
    Look at looping commands.

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      As there has been no reply, I'm closing this thread on grounds that homework problems are not allowed.

      Comment

      Working...