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?

25th Aug 2019, 3:02 AM
Raj Grewal
Raj Grewal - avatar
3 Respuestas
+ 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]);
25th Aug 2019, 6:37 AM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
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.
25th Aug 2019, 4:26 AM
Raj Grewal
Raj Grewal - avatar
0
int[] columns; // values of one row int[][] row; // add couple of values like columns = ... row[0] = columns;
25th Aug 2019, 8:48 AM
zemiak