So I'm supposed to create a Permutation list that looks like this
Output:
and I can't seem to get my code to repeat 10 times (Edit: it tells me that numbers.add(og.get(randPick)); `
is out of bounds because it becomes a negative number
CODE:
import java.util.ArrayList;
import java.util.Random;
public class ArrayListTest
{
public void Arrays(){
ArrayList<Integer> og = new ArrayList<Integer>();
Random random = new Random();
//what is inside the Array (Digits 1-10)
for (int x = 1; x <= 10; x++) {
og.add(x);
}
ArrayList<Integer> numbers = new ArrayList<Integer>();
//printing
int a = 1;
while(a < 10){
System.out.print("List " + a + ":");
a++;
for(int y = 0; y < 10; y++){
//the random number itself
int randPick = random.nextInt(og.size());
//adding the new random number to the permutation
numbers.add(og.get(randPick));
//taking out the random number slot chosen
og.remove(randPick);
//printing out the current numbers in one line
System.out.print(numbers.get(y) + " ");
}
}
}
}