Currently I have an arrayList which contains several value pairs. I'm trying to print them in matrix format as shown in the example below. Every odd number is the location in the matrix and the following number is the value. The location goes up as in a counter and if the number doesn't exist in the array a 0 is placed in it's location. Bit tricky to explain.
arraylist contains (1, 10, 2, 90, 4, 9, 7, 2, 11, 4, 14, 45)
Output:
0 10 90 0
9 0 0 2
0 0 0 4
0 0 45 0
I've tried:
int position, value;
int size = 16;
for (int i = 0 ; i < size ; i += 2) {
position = matrix.get(i);
if(position == i){
value = matrix.get(i+1);
System.out.print(value);
} else {
System.out.print("0");
}
}