-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpperTriangularMatrix.java
More file actions
31 lines (30 loc) · 1.07 KB
/
UpperTriangularMatrix.java
File metadata and controls
31 lines (30 loc) · 1.07 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
import java.io.*;
public class UpperTriangularMatrix {
public static void main() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("ENTER THE NUMBER OF ROWS =");
int m = Integer.parseInt(br.readLine());
System.out.println("ENTER THE NUMBER OF COLUMNS =");
int n = Integer.parseInt(br.readLine());
int arr[][] = new int[m][n];
System.out.println("ENTER THE ELEMENTS=");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
arr[i][j] = Integer.parseInt(br.readLine());
}
}
System.out.println("MATRIX IS=");
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n - i; j++) {
System.out.print(arr[i][j] + " ");
}
System.out.println();
}
}
}