Is quiet new to Java so not sure how to create a 3D array with for-loop array as its element:
public class Test {
public static void main(String[] args) {
int ASize = 20;
int[][] loc = new int[5][5];
for(int size = 0,xy = ASize/2; size < 5; size ++,xy += ASize) {
for(int size2 = 0,xy2 = ASize/2; size2 < 5; size2 ++,xy2 += ASize) {
loc[size][size2] = xy;
}
}
}
}
Is trying to create a 3D array with element array in form of [xy,xy2] but can't figure out the correct way to express it. Supposedly Both variable xy and xy2 increment with for-loops by ASize by 20 with initial value of ASize/2. The expected output array should be:
[10,10] [30,10] [50,10] [70,10] [90,10]
[10,30] [30,30] [50,30] [70,30] [90,30]
[10,50] [30,50] [50,50] [70,50] [90,50]
[10,70] [30,70] [50,70] [70,70] [90,70]
[10,90] [30,90] [50,90] [70,90] [90,90]
So what's the correct way to write for-loops in order to create this kind of 3D array with incrementing element arrays?
[xy, xy2].2Darray is a single dimensional array with single dimensional array elements. And they can be different sizes so you can havejaggedarrays.