ld_pvl said:
Hi,
Can anyone help me with this problem please. Say I have a 1 dimensional array with 15 spaces:
int[] Array = new int[15]
Now I want to generate random numbers and put them randomly into that Array, but the numbers must be from 1 to 15, and no numbers should repeat.
Thanks
Fun thing to do, I will help you since you might have a trouble to figure it out !
public class trythis2 {
public static void main(String[] arg) {
int[] Array = new int[15];
readIn(Array);
for(int i=0; i<15; i++) {
System.out.println("The array will contain"+Array[i]);
}
}
public static void readIn(int[] List) {
for(int j=0; j<List.length; j++) {
List[j] = (int) (Math.random()*15+1);
}
}
}
I would leave the number repeating thing to you :)
I recommend you do an second method that will allow you to set an exception on the array, if array contains same value but in different position, run again within the selected positions.
Good Luck !