-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Reverse_Diagonal_Neg.java
More file actions
48 lines (44 loc) · 1.09 KB
/
Array_Reverse_Diagonal_Neg.java
File metadata and controls
48 lines (44 loc) · 1.09 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 Array_Reverse_Diagonal_Neg {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int arr[][] = new int[4][4];
System.out.println("enter 4 elements row and column: ");
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 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 of diagonal matrix: \n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
if ((i + j) == 3) {
arr[i][j] = -1;
}
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,
//2 4 9 -1
//7 2 -1 1
//1 -1 8 3
//-1 8 0 9