Results 1 to 4 of 4
  1. #1
    Zompire is offline Member
    Join Date
    Jul 2016
    Posts
    8
    Rep Power
    0

    Default Stuck trying to take old historgram progam and changing it around

    i am drawing a blank here the original program displayed users input of integers 1-100 and displayed # in catagorys of 10 i want to change it so that it is just numbers 1-10 and displays how many times 1 was entered 2 was entered and so on here is an example of what i am trying to accomplish
    1 | #####

    2 | ##

    3 | ####################

    4 |

    5 | ###

    6 | ##########

    7 | ##

    8 | #####

    9 | ##########

    10 | ##########

    here is what is happening
    1 - 10 | ######
    here is my code so far after some adjustments i think i made things worse please help
    Java Code:
    import java.util.Scanner;
      public class histogram
        {
         public static void main (String[] args)
        {
        Scanner scan = new Scanner (System.in);
         int[] nums = new int[11];
            System.out.println("Enter numbers between 1 and 10[0 to quit]: ");
                 int num = scan.nextInt();
                 int base10 = 0;
            while (num != 0)
        {
           nums[num]++;
           num = scan.nextInt();
        }
              for (int count = 1; count <=1;count+=1)
           {
               System.out.print(count + " - " + (base10+=10) + " | " );
               for (int index = count ; index<=base10 ; index++)
           {
                 while(nums[index] > 0)
           {
                  System.out.print("#");
                   nums[index]--;
             }
         }
       }
      }
    }
    Last edited by Zompire; 07-15-2016 at 02:20 AM. Reason: change format

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Stuck trying to take old historgram progam and changing it around

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.

    Also posted here: http://www.coderanch.com/t/668096/ja...orgram#3117727
    Last edited by Norm; 07-15-2016 at 02:19 AM.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    Zompire is offline Member
    Join Date
    Jul 2016
    Posts
    8
    Rep Power
    0

    Default Re: Stuck trying to take old historgram progam and changing it around

    i hope i did it right now thank you again i am new to this

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Stuck trying to take old historgram progam and changing it around

    Ok, that's a lot better. First step I recommend is to print out the contents of the array to see if the counts are correct. Use the Arrays class's toString method:
    Java Code:
      System.out.println("an ID "+ java.util.Arrays.toString(theArrayName));
    If that looks ok, move to printing the report: One line per element in the array
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Stuck already!
    By zb82 in forum New To Java
    Replies: 8
    Last Post: 05-09-2013, 12:31 AM
  2. I can compile my progam but I can't run it!
    By mikaelafiery in forum New To Java
    Replies: 13
    Last Post: 07-04-2012, 09:45 AM
  3. Replies: 0
    Last Post: 08-14-2010, 10:09 AM
  4. really stuck now..
    By shongo in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2008, 02:56 AM
  5. Stuck in need of help!
    By Zombie_Leg! in forum New To Java
    Replies: 1
    Last Post: 09-23-2008, 02:22 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •