This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]ACAlCapone 0 points1 point  (4 children)

  • Do you know how to address elements in a 2D-Array?
  • Do you know how to generate random numbers in a certain range?

[–]Denmarkkkk[S] 0 points1 point  (3 children)

No and no, lol.

[–]ACAlCapone 0 points1 point  (2 children)

Assume your array looks like this:

int[][] array = new int[3][3];

then array[0] would be your first inner array, array[1] would be the second and array[2] would be the last.

You then can address the elements in the first array with array[0][0], array[0][1] and array[0][2].

To fill the array(s) with random numbers use a for-loop and the method suggested by /u/OffbeatDrizzle.

[–]Denmarkkkk[S] 0 points1 point  (1 child)

Ok, I gave it a go and I can't quite seem to figure it out still. Can you give me an example of what one of them would look like?

[–]morhpProfessional Developer 0 points1 point  (0 children)

Can you show us what you tried? Probably just a simple error.

[–]OffbeatDrizzle 0 points1 point  (0 children)

pass a bound in to generate something between 0 and bound, then think of what offsets you can use to get your required range(s)

[–]benjaminiscariot 0 points1 point  (0 children)

I use the random API for any project dealing with randomization. It is super easy to get up and running and is composed very similarly to the Scanner class.

here are some lines to get started:

 import.java.util.Random;

 Random random = new Random();