Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Highschool student in need of help with array problem! Please Help!

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Highschool student in need of help with array problem! Please Help!

    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[ # ]; "
    and my brackets. Anyway, someone please help this desperate lady


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    18,665
    Thanks
    45
    Thanked 1,960 Times in 1,934 Posts

    Default Re: Highschool student in need of help with array problem! Please Help!

    Can you copy the full text of the error messages and post it here?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/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.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Highschool student in need of help with array problem! Please Help!

    Just to get you started:

    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...

  4. #4
    Junior Member
    Join Date
    Feb 2013
    Location
    N. Ireland
    Posts
    29
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default Re: Highschool student in need of help with array problem! Please Help!

    1 way to do this would be :

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

Similar Threads

  1. problem of remove student from list
    By pig-rabbit in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 29th, 2012, 07:14 AM
  2. Help out a poor student!
    By Hoor-paar-kraat in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 4th, 2012, 07:04 PM
  3. Print Student average, high, and low grades through array?
    By MLeclerc182 in forum Object Oriented Programming
    Replies: 2
    Last Post: May 10th, 2012, 06:12 AM
  4. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  5. Java program for 2-D Array Maze
    By Peetah05 in forum Collections and Generics
    Replies: 11
    Last Post: May 8th, 2009, 04:30 AM

Tags for this Thread