1. Member
Join Date
Oct 2010
Posts
81
Rep Power
0

## question help

my assignment is asking me to make an application to read a number of integers from a range to 0-50 inclusive and counts how many times each one is entered, and print all the values after it is processed with the number of times its been entered.
would i need to implement a scanner of some sort.
im not getting exaclty what im supposed to do :/

2. Member
Join Date
Oct 2010
Posts
81
Rep Power
0
we are dealing with arrays

3. You will want a Scanner, yes. You will also have an array of some set size (depending on how many integers you want to store), of type Integer. Then you want to check each nextInt from the scanner to see if it is from 0-50. If it is, store it in the array, then increment an index.

This is about the best I can give you--once we see a solid effort on your part, a code or algorithm or even a concept, we can go from there.

4. Member
Join Date
Oct 2010
Posts
81
Rep Power
0
the directions of the program is to read integers from 0-50 inclusive and counts how many times each one is entered. After all the input has been processed, print all the vlaues, with the number of each times each was printed.

i have this so far

Java Code:
```public class count {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int[] intArray= new int[]{0,101,9,42,47,50,93};
for (intArray =0; intArray <=50; intArray++);
System.out.println(count);

}

}```
is this correct so far, im not exactly sure how to print the number of times each one was entered

5. Alright, there's a few issues with what you've got.

First, avoid naming your class something like "count". It's not descriptive nor helpful for you or anyone else on your project. If it's your main class (which it is), perhaps something like countArrayAssignment or something (be creative!).

Next, in the code you've provided, the array is hardcoded. In your program you will want to avoid doing this as the numbers will actually be provided by the user. Have a look at this link, and you can see by the first code example how you will want to declare your array. (Remember to avoid C&P'ing the whole thing in there--realize what each part of the code is for before you use it.) Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

Now, your for loop is a bit odd. You've simply created it and it does nothing. Basically, in English, it's saying "set your array to zero (which can't be done), then increment this value (also cannot be done), then do nothing." Instead, you'll want something like this:
Java Code:
```for (int i = 0; i < intArray.length; i++) {
// Some new code will go on this line in the future.
}```
(Here is some information on array lengths and array looping: http://www.vias.org/javacourse/chap10_05.html)

And finally, when you do the print line statement, you are simply printing the value of your class, which isn't valid nor practical. Instead, you will want to have created a variable called count before your loop starts.

I think you're starting on the right track though. Once you've cleaned up the above, paste your new code and we'll keep on going.

#### Posting Permissions

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