0
[JAVA 2D ARRAY] How to declare contents of row and column separately
Iâm doing a lab and Iâm stuck with trying to store the âROWâ and âCOLUMNSâ in separate variables for a 2D array. Unfortunately although there might be simpler alternatives, this is how Iâm instructed to do it. The array will be initialised later in a different class. For now all I need to do is store a variable named ârowâ with a couple numbers, and another variable named âcolumnsâ with a couple values also. The variables have already been instanced as shown below, and now I will put the values of array row & column in a method. - int row - char column Whatâs the best way I can do this please?
3 Answers
+ 10
I think this is you want Raj Grewal
int[][] _2d = new int[8][10];
int arr[] = {1,2,3,4,5};
int arr1[] = {6,7,8,9,0};
_2d[0]=arr;
_2d[1]=arr1;
System.out.println(_2d[0][2]);
System.out.println(_2d[1][2]);
0
I donât believe Jagged Array is what iâll need akshay harshora.
The array will have 8 rows and 10 columns later, all I need to do is store the row in a variable named âint rowâ and then store the values â[1,2,3,4,5,6,7,8,9,10]â
The variables wonât point to the 2D array yet, just storing for when I use the method later.
0
int[] columns;
// values of one row
int[][] row;
// add couple of values like
columns = ...
row[0] = columns;