0

Is it possible to store 2, (5,12)both numbers are together, 3, (5,12), 3, (5,12) in an array in java?, if possible, how?

6th Sep 2018, 8:25 PM
Illegal
Illegal - avatar
8 Respostas
+ 4
The code I gave is a full class definition. It stores the two properties: num and array. It has a constructor to store the two items in the instance, when it is created. Data data[] = {new Data(2, new int[] {5,12}), new Data(3, new int[] {6, 11})} This would make an array with two elements. The first has num of 2 and array with two elements 5 & 12. The second has num of 3 and array with two elements 6 & 11.
6th Sep 2018, 10:54 PM
John Wells
John Wells - avatar
+ 1
You could make a class with two properties: class Data { int num; int array[]; Data(int num, int array[]) { this.num = num; this.array = array; } } Then, make a single dimensional array of it.
6th Sep 2018, 10:12 PM
John Wells
John Wells - avatar
+ 1
I'm not sure what part you are asking about: classes or arrays. Personally, you should continue learning via the course. You need those basics to understand this.
6th Sep 2018, 11:59 PM
John Wells
John Wells - avatar
0
You could create a matrix (multidimensional array) and do it like this int[][] array = {{3},{5,12}}; System.out.println(array[0][0]); //3 System.out.println(array.[1][0]); //5 System.out.println(array[1][1]); //12 but this may not be the beat solution for you
6th Sep 2018, 8:35 PM
Daniele Bonomi
Daniele Bonomi - avatar
0
i'm gonna try it with matrix.......but is there any way to use one dimensional array
6th Sep 2018, 8:52 PM
Illegal
Illegal - avatar
0
i don't think i understand.......i have not gotten to that stage in java,i'm still a beginner. sir please explain.
6th Sep 2018, 10:17 PM
Illegal
Illegal - avatar
0
i think i understood a little bit.....assuming i wanted to research on this, what topic should i research on
6th Sep 2018, 11:41 PM
Illegal
Illegal - avatar
0
okay. Thank you very much sir
7th Sep 2018, 6:46 AM
Illegal
Illegal - avatar