-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReplace_Even_Num_0.java
More file actions
48 lines (44 loc) · 1.05 KB
/
Replace_Even_Num_0.java
File metadata and controls
48 lines (44 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package Arrays2D;
import java.util.Scanner;
public class Replace_Even_Num_0 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the array elements:\n");
int arr[][] = new int[4][4];
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
arr[i][j] = sc.nextInt();
}
System.out.println();
}
System.out.print("\nThe input for the array elements:\n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
System.out.print("\nthe output array elements:\n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if ((arr[i][j]) % 2 == 0) {
arr[i][j] = 0;
}
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
sc.close();
}
}
//Eg: if your input is,
//2 4 9 0
//7 2 1 1
//1 5 8 3
//6 8 0 9
//The output should be,
//0 0 9 0
//7 0 1 1
//1 5 0 3
//0 0 0 9