1amitgls
BAN USERpublic static void replaceRowNcolumWith0(){
int matricArray[][] = new int[][]{{1,2,3,5},{5,6,0,43},{9,10,11,6},{13,14,15,8},{1}};
int row = 0,col = 0; // A element's row number and column number which is 0.
for(int i=0;i<matricArray.length;i++){ // find where exactly is 0
for(int j=0;j<matricArray[i].length;j++){
System.out.print(matricArray[i][j]+" ");
if(matricArray[i][j] == 0){
row = i;
col = j;
}
}
System.out.println();
}
for(int k=0;k<matricArray.length;k++){ // replace row and column with 0
for(int l=0;l<matricArray[k].length;l++){
if(row==k || col==l)
matricArray[k][l] = 0;
}
}
for(int i=0;i<matricArray.length;i++){ // print matric
for(int j=0;j<matricArray[i].length;j++){
System.out.print(matricArray[i][j]+" ");
}
System.out.println();
}
}
If we will add one more row in array {1}, it will not work. will throw exception.
- 1amitgls January 15, 2014