• January 25th, 2013, 09:29 PM
pegasus949
So I am in a computer science class at my school and there is this one program that I can't seem to figure out! If anyone here would like to help, I really appreciate it! Could someone explain to me how to do the for loops? Well here's the objective:

Design and implement an application that reads a set of values in the range 1 to 100 from the user and then creates a chart showing how often the value appeared. The chart should look like the one shown here. It shows how many values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered.
1-10 *****
11-20 **
21-30 *******************
31-40
41-50 ***
51-60 ********
61-70 **
71-80 *****
81-90 *******
91-100 *********

Here's what I have so far:

import java.util.Scanner;
public class C6p4
{
public static void main (String[] args)
{
Scanner kb = new Scanner(System.in);
int[] count = new int[10];
int num;
if (num >= 1 && num <= 10)
count[0];
if (num >= 11 && num <= 20)
count[1];
if (num >= 21 && num <= 30)
count[2];
if (num >= 31 && num <= 40)
count[3];
if (num >= 41 && num <= 50)
count[4];
if (num >= 51 && num <= 60)
count[5];
if (num >= 61 && num <= 70)
count[6];
if (num >= 71 && num <= 80)
count[7];
if (num >= 81 && num <= 90)
count[8];
if (num >= 91 && num <= 100)
count[9];
}
for ( int i = 0; i < 9; i ++)
{
System.out.print(" ");
for ( int j = 1; j < count[i]; j ++)
{
System.out.print("*");
}
}
}

I'm using Eclipse and it says there's a syntax error with all the "count[ # ]; "
• January 26th, 2013, 06:25 AM
Norm
Can you copy the full text of the error messages and post it here?

[code=java]
[/code]
to get highlighting and preserve formatting.

What are the count[#] statements supposed to do? There is no operation being done with the values/variables.
• January 28th, 2013, 04:52 AM
Starstreak
Just to get you started:

Code :

```if (num >= 1 && num <= 10) count[0];```

What did you intend with the count array? At the moment it isn't a proper statement. It needs something done to it, like printing it out, assigning it to a variable, or adding a number to it etc...
• March 5th, 2013, 05:36 PM
StephenCoyle
1 way to do this would be :

Code :

```String 1to10;   if (num >= 1 && num <= 10) 1to10 += "* ";```