-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSumOf2DArray_EvenArray.java
More file actions
51 lines (46 loc) · 1.21 KB
/
SumOf2DArray_EvenArray.java
File metadata and controls
51 lines (46 loc) · 1.21 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
49
50
51
package Arrays2D;
import java.util.Scanner;
public class SumOf2DArray_EvenArray {
// Offline Assignment - 2D Array Processing
// create a 4X4 array -- Replace the values as 0 whose sum of indexes is even.
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Array Elements of 4x4 Matrix: ");
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("\t");
}
System.out.println("\nThe input Array elements matrix is: \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 array elements whose sum of indices are even: \n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if((i+j)%2==0) {
arr[i][j] =0;
}
System.out.print(arr[i][j]+"\t");
}
System.out.println();
}
sc.close();
}
}
//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 4 0 0
//7 0 1 0
//0 5 0 3
//6 0 0 0