need help with arrays..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ashley514
    New Member
    • May 2007
    • 1

    need help with arrays..

    Yeah so I've been taking java programming as an elective course in school and I don't really understand how to use arrays and stuff. He's like flying through this chapter and I'm not picking it up at all. gah. I'm so stressed out. Now he assigned this program as a test grade:

    "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. The chart should look like the one shown. It shows how many values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for every value entered. "

    I have no idea where I'm going with this! And he wants us to use "0" to exit. I'm losing my mind. I've started this program over like 5 times. I'm not asking anyone to do this for me but i realllyyy need help with the array part.

    the last time i asked for help somewhere everyone yelled at me. haha. please don't kill me.
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by ashley514
    Yeah so I've been taking java programming as an elective course in school and I don't really understand how to use arrays and stuff. He's like flying through this chapter and I'm not picking it up at all. gah. I'm so stressed out. Now he assigned this program as a test grade:

    "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. The chart should look like the one shown. It shows how many values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for every value entered. "

    I have no idea where I'm going with this! And he wants us to use "0" to exit. I'm losing my mind. I've started this program over like 5 times. I'm not asking anyone to do this for me but i realllyyy need help with the array part.

    the last time i asked for help somewhere everyone yelled at me. haha. please don't kill me.
    Post your best attempt at it so far and indicate the area you're having the most difficulty with.

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      You can compare arrays with streets where a row of identical houses is located.
      The name of the array is the name of the street. All houses have a number,
      starting at zero and the house numbers increment by a step equal to one,
      so house#0 house#1 house#2 ... etc. The numbers are analgous to house numbers.

      In Java the houses have a type as all variables in Java have a type. Suppose
      I have an array named 'count' with 100 'houses' or values:
      Code:
      int[] count= new int[100];
      The 100 values are accessed as count[0], count[1], count[2] ... etc. up to
      count[99] (check it out: 0, 1, 2 ... 99 are hundred numbers). Each value has
      type 'int'.

      Suppose I have a variable 'x' with a value in the range [0, 99]. I can use it to
      access one of the values in the count array; the following example adds one to
      the previous value in that variable ('house'):
      Code:
      count[x]= count[x]+1; // or: count[x]++ if you like
      Normal variable have just a name; an array variabe has a name (a 'street name')
      and an index number (a 'house number')

      Does this help you out a bit?

      kind regards,

      Jos

      Comment

      • rsrinivasan
        New Member
        • Mar 2007
        • 221

        #4
        Hi,
        I just did one java program what u ask. Instead of getting values from keyboard it gets 100 random value. If you want to get from keyboard use the class BufferedInputSt ream. Run it and ask any other Clarifacations.

        <code removed; we don't spoonfeed posters>

        Thanks,
        Srinivasan r.
        ----------------------------------------------------------------------------------------------------
        We appreciate your intentions to help; we really do. Spoonfeeding a poster
        with complete running code doesn't help them out though. They won't learn
        anything from it and they may be tempted to hand in your work as if it were
        their own homework. That would be theft or plagiarism. Thank you for your
        cooperation.

        kind regards,

        Jos
        Last edited by JosAH; May 16 '07, 09:35 AM. Reason: no boilerplate code allowed.

        Comment

        Working...