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?
8 Answers
+ 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.
+ 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.
+ 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.
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
0
i'm gonna try it with matrix.......but is there any way to use one dimensional array
0
i don't think i understand.......i have not gotten to that stage in java,i'm still a beginner.
sir please explain.
0
i think i understood a little bit.....assuming i wanted to research on this, what topic should i research on
0
okay.
Thank you very much sir