-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProgram9.java
More file actions
24 lines (23 loc) · 823 Bytes
/
Copy pathProgram9.java
File metadata and controls
24 lines (23 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// WAP to accept a 3 x 3 matrix from the user and display the left diagonal elements only
import java.util.Scanner;
public class Program9 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[][] arr = new int[3][3];
System.out.println("Enter the elements of the matrix: ");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = sc.nextInt();
}
}
System.out.println("The left diagonal elements are: ");
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
if (i == j) {
System.out.println(arr[i][j] + " ");
}
}
}
sc.close();
}
}