Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ReemplazarCeros {
- public void reemplazarCeros(Double valores[][]) {
- for (int i = 0; i < valores.length; i++) {
- for (int j = 0; j < valores[i].length; j++) {
- if (valores[i][0] == 0) {
- valores[i][j] = valores[i][j + 1];
- }
- if(valores[i][valores[i].length-1] == 0){
- valores[i][valores[i].length-1] = valores[i][valores[i].length-2] ;
- }
- if (valores[i][j] == 0) {
- valores[i][j] = ((valores[i][j - 1] + valores[i][j + 1]) / 2);
- }
- }
- }
- for (int i = 0; i < valores.length; i++) {
- for (int j = 0; j < valores[i].length; j++) {
- System.out.print(valores[i][j] + " ");
- }
- System.out.println();
- }
- }
- public static void main(String[] args) {
- ReemplazarCeros test = new ReemplazarCeros();
- Double[][] vector = { { 1.0, 0.0, 3.0 }, { 0.0, 3.0, 4.0 },
- { 2.0, 6.0, 0.0 } };
- test.reemplazarCeros(vector);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement