An application that reads numbers in the range of 0 to 50

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JinFTW
    New Member
    • Feb 2008
    • 12

    An application that reads numbers in the range of 0 to 50

    I'm trying to create an application that reads an arbitrary number of integers that are in the range 0 to 50 and counts how many occurrences of each are entered. At the end of the input processing, I have to print all of the values (including number of occurrences) that were used one or more times.

    So far I've set up the scanner, and I had originally thought to use a number of scan.nextInt() in order to calculate each and every one, but I simply can't develop the right counters and link the concepts. Any help would be greatly appreciated!
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    Originally posted by JinFTW
    I'm trying to create an application that reads an arbitrary number of integers that are in the range 0 to 50 and counts how many occurrences of each are entered. At the end of the input processing, I have to print all of the values (including number of occurrences) that were used one or more times.

    So far I've set up the scanner, and I had originally thought to use a number of scan.nextInt() in order to calculate each and every one, but I simply can't develop the right counters and link the concepts. Any help would be greatly appreciated!
    Post your best effort and ask a specific question about it.

    Comment

    • JinFTW
      New Member
      • Feb 2008
      • 12

      #3
      Originally posted by BigDaddyLH
      Post your best effort and ask a specific question about it.
      This is how far I've gotten, I realize there are a number of mistakes, but I'm currently working on it.


      [CODE=Java]import java.util.Scann er;
      public class Numbers
      {
      public static void main (String[] args)
      {
      Scanner scan = new Scanner (System.in);
      final int MAXNUM = 51;
      int[] list = new int [MAXNUM];

      int current=0;

      System.out.prin tln ("Enter a series of numbers between 1 and 50: ");
      int number = scan.nextInt();

      for (int index = 0; index < 50; index++)
      {
      list[index]++;



      }
      for (int index = 0; index < list.length; index++)
      {
      System.out.prin t ();

      }

      }
      }[/CODE]
      Last edited by BigDaddyLH; Feb 26 '08, 09:25 PM. Reason: added code tags

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Please enclose your posted code in [code] tags (See How to Ask a Question).

        This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

        Please use [code] tags in future.

        MODERATOR

        Comment

        • BigDaddyLH
          Recognized Expert Top Contributor
          • Dec 2007
          • 1216

          #5
          Don't forget part B: ask a specific question!

          Comment

          • JinFTW
            New Member
            • Feb 2008
            • 12

            #6
            I'm simply wondering how you use an array to give the number of occurrences for each integer that the user enters.

            Comment

            • BigDaddyLH
              Recognized Expert Top Contributor
              • Dec 2007
              • 1216

              #7
              Originally posted by JinFTW
              I'm simply wondering how you use an array to give the number of occurrences for each integer that the user enters.
              Like what you've done, except after you get the verified input -- call it number, you:

              [CODE=Java]list[number]++;[/CODE]
              because list[number] records the count of times number was input (not the best name: "list")

              Comment

              • JinFTW
                New Member
                • Feb 2008
                • 12

                #8
                Thank you so much! I think I can see where it's going now, much appreciated to you for clearing that up!

                Comment

                • JinFTW
                  New Member
                  • Feb 2008
                  • 12

                  #9
                  Ok after adding list[number]++;
                  and looking at the problem itself, it appears as though I'm only taking in one value from the user. I hate to bother you guys with this, but I suppose I have another question here, do I need another for loop in this statement? Or am I supposed to use an if-else in order to have this thing read the user's answers again and again?

                  Comment

                  • BigDaddyLH
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1216

                    #10
                    Originally posted by JinFTW
                    Ok after adding list[number]++;
                    and looking at the problem itself, it appears as though I'm only taking in one value from the user. I hate to bother you guys with this, but I suppose I have another question here, do I need another for loop in this statement? Or am I supposed to use an if-else in order to have this thing read the user's answers again and again?
                    How else can you execute something repeatedly?

                    Comment

                    Working...