473,320 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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:

Expand|Select|Wrap|Line Numbers
  1. //*****************************************************************
  2. //Histogrm1.Java
  3. //
  4. //Java program that takes numerical inputs between 1-100 and prints
  5. //them in to categories of 10 with a * to represent each 5 number
  6. //values
  7. //*****************************************************************
  8.  
  9. import java.io.*;
  10. public class Histogram1 {
  11.  
  12.    // Main method
  13.    public static void main(java.lang.String[] args) throws IOException {
  14.  
  15.       //Storage of int 
  16.       DataInputStream stdin = new DataInputStream (System.in);
  17.       final int MAXRANGE = 10;       
  18.       final int MINRANGE = 1;         
  19.       final int RANGE    = 10;       
  20.  
  21.       int[] list = new int[MAXRANGE]; 
  22.  
  23.       for (int i=0; i<list.length; i++) {
  24.          list[i] = 0;
  25.       }
  26.  
  27.       // Enter Integers of range
  28.       System.out.println ("Enter some numbers between 1 and 100.");
  29.       System.out.println ("Signal the end by entering a number outside of that range.");
  30.  
  31.       // Entering the actual number
  32.       System.out.print ("Enter Integer: ");
  33.       int value = Integer.parseInt (stdin.readLine());
  34.  
  35.       // Will keep adding integers within range
  36.       while (value >= MINRANGE && value <= (MAXRANGE*RANGE)) {
  37.  
  38.          // Range
  39.          list[(value-1)/RANGE] = list[(value-1)/RANGE] + 1;
  40.  
  41.          // Enter next integer
  42.          System.out.print ("Enter Integer: ");
  43.          value = Integer.parseInt (stdin.readLine());
  44.       }
  45.  
  46.       // Print histogram
  47.       System.out.println ("\nThis is the histogram:");
  48.       for (int i=0; i<list.length; i++) {
  49.  
  50.          System.out.print ("   " + (i*RANGE+1) + " - " + (i+1)*RANGE + "\t| ");
  51.  
  52.          // Print *
  53.          for (int j=0 ; j<list[i] ; j++) {
  54.             System.out.print ("*");
  55.          }
  56.          System.out.println ();  
  57.       }
  58.    }
  59. }
Oct 4 '12 #1
2 2410
zmbd
5,501 Expert Mod 4TB
This reads very much like a homework question...
Benefit of the doubt?
Look at looping commands.
Oct 4 '12 #2
zmbd
5,501 Expert Mod 4TB
As there has been no reply, I'm closing this thread on grounds that homework problems are not allowed.
Oct 5 '12 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Oracle3001 | last post by:
Hi All, I am trying to use JAI to build a histogram of an image i have. I have posted the code below, and the error I get at runtime. I have taken the code from the offical java examples, so I am...
10
by: Starting_Anew | last post by:
Hi i just started a programing class a few weeks ago. and i need help drawing lines...I know this may seem very simple to everyone here but i am struggling. Ok I am writing a program to create a...
27
by: ext_u | last post by:
Ok I thought I would try to take the program one thing at a time. (If you remember my last post I am trying to make a histogram with data on the size of each word) Anways first .. I obviously...
1
by: yaron | last post by:
Hi all, I am building an application that use SecureSocket between java and c#. I found that java need a "keystore" to communicate while c# use cert like ..cer or .p12 or .pfx , etc. I have...
2
by: Daniel Nogradi | last post by:
How does one do a histogram on only a part of an image? This is what I found in the PIL documentation about histogram( ): """ im.histogram(mask) =list Returns a histogram for those parts of...
5
by: arnuld | last post by:
this is a programme that counts the "lengths" of each word and then prints that many of stars(*) on the output . it is a modified form of K&R2 exercise 1-13. the programme runs without any...
1
by: ray2007colon | last post by:
I need to now how to compare the elements of two arrays. Here is my program. Now I need to compare each element. So I can print the arrays and the elements that are not the same. import...
5
by: smileskhan | last post by:
Hay Friends... Here I started a new and interested thread. I hope you also enjoy it. I got a task to creat a Hospital Database in Java. But I don´t have any good clues abouts it....
1
by: timothy ma and constance lee | last post by:
Sirs/Madam I encounter the problem on date field. Sometimes, when there is no date, then it will return the null object. When I want to check by aDate.toString() = "" or null, it throws...
1
by: balucec | last post by:
Please explain the steps to create a histogram for a binary image using JAVA(JAI). I m working out a project wherein I need to separate single sentences (individual lines only; not upto full...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.