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 5 of 5

Thread: Number Counting Array issues

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    My Mood
    Yeehaw
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Number Counting Array issues

    My assignment is this:
    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 values appeared.
    This is my code so far:
    import java.util.*;
    public class chap6pp4 { //this is just the assignment number in my textbook-- chapter 6 programming project 4
     
        public static void main() 
        {
            int numbers[] = new int[10];
            int appearNum;
     
            Scanner scan = new Scanner (System.in);
     
            System.out.println("Enter a set of values from 1 to 100: ");
            appearNum = scan.nextInt();
     
            while (appearNum >= 1 && appearNum <= 100)
            {
                numbers[(appearNum--) / 10]++;
     
                System.out.println("Enter another number (-1 to quit): ");
                appearNum = scan.nextInt();
            }
     
            System.out.println();
     
            for (int i = 0; i < numbers.length; i++)
            {
                System.out.print ("   " + (i*11) + " - " + (i+1)*10 + "\t| ");
     
                for (int j = 0; j < numbers.length; j++) 
     
                {
     
                    System.out.print ("*");
     
                }
     
     
                System.out.println (); 
     
            } 
     
        }
     
    }

    So it compiles, but when I try to run the code by putting some numbers in it keeps on asking me to put more numbers in, or press -1 to quit. When I do -1, it shows a full asterisk chart.
    This is what it looks like :
    Enter a set of values from 1 to 100:
    1 2 4 64 33 33 52 74 74 2 44
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    2 2 44 33 33
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    Enter another number (-1 to quit):
    -1

    0 - 10 | **********
    11 - 20 | **********
    22 - 30 | **********
    33 - 40 | **********
    44 - 50 | **********
    55 - 60 | **********
    66 - 70 | **********
    77 - 80 | **********
    88 - 90 | **********
    99 - 100 | **********

    those inputted numbers are mine. This is what I want the chart to look like, but the program isn't running the way it is supposed to and I don't know why.
    Any help is much appreciated!


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Number Counting Array issues

    You're on the right track but need to give it a bit more thought. You should ask yourself, "Is the program written to accept a bunch of numbers entered on a single line?", and "Why are 10 stars printed for every value?" The answers to these questions are fairly simple and obvious and should point you to logic corrections.

  3. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    My Mood
    Yeehaw
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Number Counting Array issues

    thanks. i went through again after posting and realized a couple dumb things i did wrong, I'm just having issues with printing things for specific answers within a group.

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Number Counting Array issues

    I'm just having issues with printing things for specific answers within a group.
    Can you explain what this means? It sounds like you're talking about a different problem entirely. "Printing things," (what things?), "specific answers," (what answers to what questions?, and "within a group" (what group?) don't make much sense. I can almost connect "group" to the frequency range you're collecting, but I'm not sure that's right. Don't talk in riddles.

  5. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    6
    My Mood
    Yeehaw
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Number Counting Array issues

    i was dismissing my issue as one based in dumb things that i didn't do. i meant that i was having issues printing the asterisk for each set of 10 answers within each individual set without making a different section for each 10.
    hardly a riddle.

Similar Threads

  1. Array counting problem
    By Variumzky in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 2nd, 2013, 12:24 PM
  2. Replies: 2
    Last Post: June 4th, 2013, 08:09 PM
  3. [SOLVED] counting number of comparisons in merge sort
    By mia_tech in forum What's Wrong With My Code?
    Replies: 9
    Last Post: May 26th, 2012, 11:54 PM
  4. Reading text file and counting the number of words, integers, and floats.
    By Jsmooth in forum File I/O & Other I/O Streams
    Replies: 11
    Last Post: April 12th, 2012, 06:39 PM
  5. Issues with ascending number program
    By newtojava2011 in forum What's Wrong With My Code?
    Replies: 21
    Last Post: June 30th, 2011, 06:23 PM

Tags for this Thread