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?

23rd Oct 2019, 3:20 PM
Preet
4 Respostas
+ 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)
23rd Oct 2019, 6:34 PM
Sumit Programmer😎😎
Sumit Programmer😎😎 - avatar
+ 2
If this is an int[][] array then it is already assigned with 0(zero) value . No cell will be left empty .
23rd Oct 2019, 4:03 PM
veeresh raju
veeresh raju - avatar
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;
23rd Oct 2019, 4:07 PM
Seb TheS
Seb TheS - avatar
0
And how can I check with the help of if else, whether an index is empty?
23rd Oct 2019, 4:15 PM
Preet