Remove Even Element from 2 Dimensional Array

package org.wesome.dsalgo;

public class RemoveEvenNumber {
    public static int[][] removeEvenNumber(int[][] arr) {
        printArr(arr);
        for (int row = 0; row < arr.length; row++) {
            for (int col = 0; col < arr[row].length; col++) {
                if (arr[row][col] % 2 == 0) {
                    arr[row][col] = 0;
                }
            }
        }
        return arr;
    }

    public static void printArr(int[][] arr) {
        for (int row = 0; row < arr.length; row++) {
            for (int col = 0; col < arr[row].length; col++) {
                System.out.print(arr[row][col] + " ");
            }
            System.out.println("\n");
        }
    }
}
package org.wesome.dsalgo;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.wesome.dsalgo.RemoveEvenNumber.printArr;
import static org.wesome.dsalgo.RemoveEvenNumber.removeEvenNumber;

public class RemoveEvenNumberTest {
    @Test
    void RemoveEvenNumberTest1() {
        int[][] arr = new int[][]{{1, 2, 3},
                {4, 5, 6}};
        int[][] result = removeEvenNumber(arr);
        printArr(result);
        assertAll(() -> assertArrayEquals(new int[]{1, 0, 3}, result[0]),
                () -> assertArrayEquals(new int[]{0, 5, 0}, result[1]));
    }

    @Test
    void RemoveEvenNumberTest2() {
        int[][] arr = new int[][]{{11, 22, 33},
                {44, 55, 66},
                {77, 88, 99}};
        int[][] result = removeEvenNumber(arr);
        printArr(result);
        assertAll(() -> assertArrayEquals(new int[]{11, 0, 33}, result[0]),
                () -> assertArrayEquals(new int[]{0, 55, 0}, result[1]),
                () -> assertArrayEquals(new int[]{77, 0, 99}, result[2]));
    }
}
plugins {
    id 'java'
    id "io.freefair.lombok" version "6.2.0"
}

group = 'org.wesome'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_1_8

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation 'org.junit.jupiter:junit-jupiter:5.6.2'
}

test {
    useJUnitPlatform()
}

 

follow us on