1. Member
Join Date
Nov 2013
Posts
2
Rep Power
0

## 1-D Array Help

Hey, so I'm new to java and the AP Comp Sci class I'm taking is kicking my ass. I've been working on this problem for a couple hours but can't seem to figure out what to do:

Problem: Create a list of 100 randomly generated numbers (between 1 and 100). Print the list out in order, print the list out in reverse order, print out how many of each number was generated.

I'm at a loss for the second and third part, but it's the first part I've been unsuccessfully going at for a while. Here's the code as it is right now:

//import arraylist
import java.util.ArrayList;
//import random generator
import java.util.Random;
//name class
public class NumberArray {
//string args
public static void main (String[] args) {
numbers = new ArrayList();
}
}
//method this up
public double NumListGenerator(int count) {
//make a random generator
Random generator = new Random();
//import the array
int[] Num;
//Set the array to 100
Num = new int [100];
//now let's do a for loop to come up with our 100 numbers
for (count = 0; count < 100; count++) {
//Obtain a new number
Num[count] = generator.nextInt(100) + 1;
}
return Num[count];

}
}

I've been reading a couple java books but they're not really helping, so any help is much appreciated!

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: 1-D Array Help

The term, "in order" seems ambiguous to me. Does it mean, in sorted order, or just in the order the array was populated?

Regards,
Jim

3. Member
Join Date
Nov 2013
Posts
2
Rep Power
0

## Re: 1-D Array Help

I think it's the order the numbers are generated?

4. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
6,226
Rep Power
14

## Re: 1-D Array Help

First you should place your code between code tags [code][/code]. I have done it here for you. And your comments are not
helping as they are stating the obvious. You only need to comment when something is not obvious or could be misinterpreted.

Java Code:
```import java.util.ArrayList;
import java.util.Random;
public class NumberArray {
public static void main (String[] args) {
numbers = new ArrayList();
}
}
public double NumListGenerator(int count) {
Random generator = new Random();
int[] Num;
Num = new int [100];
for (count = 0; count < 100; count++) {
Num[count] = generator.nextInt(100) + 1;
}
return Num[count];
}
}```
First, you should stay away from methods in this case. They aren't necessary (unless the prof required them). Just
do it all in main if you are permitted.

The first thing you should do is simply create a list of 100 numbers between 1 and 100. Then print them out. Once you get that
part done, then move on to the next part.

Regards,
Jim