Advertisement
MarceloVega

Untitled

Nov 12th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. class ReemplazarCeros {
  2.     public void reemplazarCeros(Double valores[][]) {
  3.         for (int i = 0; i < valores.length; i++) {
  4.             for (int j = 0; j < valores[i].length; j++) {
  5.                 if (valores[i][0] == 0) {
  6.                     valores[i][j] = valores[i][j + 1];
  7.                 }
  8.                
  9.                 if(valores[i][valores[i].length-1] == 0){
  10.                     valores[i][valores[i].length-1] = valores[i][valores[i].length-2] ;
  11.  
  12.                 }
  13.  
  14.                 if (valores[i][j] == 0) {
  15.                     valores[i][j] = ((valores[i][j - 1] + valores[i][j + 1]) / 2);
  16.                 }
  17.             }
  18.  
  19.         }
  20.        
  21.         for (int i = 0; i < valores.length; i++) {
  22.             for (int j = 0; j < valores[i].length; j++) {
  23.                 System.out.print(valores[i][j] + "  ");
  24.             }
  25.            
  26.             System.out.println();
  27.         }
  28.     }
  29.  
  30.     public static void main(String[] args) {
  31.         ReemplazarCeros test = new ReemplazarCeros();
  32.         Double[][] vector = { { 1.0, 0.0, 3.0 }, { 0.0, 3.0, 4.0 },
  33.                 { 2.0, 6.0, 0.0 } };
  34.         test.reemplazarCeros(vector);
  35.        
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement