0
Multidimensional array
Suppose I have this matrix: 1 2 3 4 5 <--------index [1][2] is empty 6 7 8 How can I fill the index [1][2] with a value zero?
4 Antworten
+ 9
By default array values are filed with 0
For checking index value is empty or not
If(arr[1][2]==0)
print(empty)
else
print(filled)
+ 2
If this is an int[][] array then it is already assigned with 0(zero) value . No cell will be left empty .
0
You could create an array of 3 elements, put there 4 and 5, and then put 0, and replace the old array from the matrix with the new array.
int[][] arr = {{1, 2, 3}, {4, 5}, {6, 7, 8}};
int[] temp = {arr[1][0], arr[1][1], 0};
arr[1] = temp;
0
And how can I check with the help of if else, whether an index is empty?