-
Notifications
You must be signed in to change notification settings - Fork 61
/
UpperTriangularMatrix.java
61 lines (58 loc) · 1.04 KB
/
UpperTriangularMatrix.java
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
52
53
54
55
56
57
58
59
60
61
package com.java.matrix;
/*
* Print the Upper Triangular Matrix of Given Matrix
* -------------------------------------------------
* say Given Matrix is
* 1 1 1
* 2 2 2
* 3 3 3
*
* Upper Triangular Matrix is
* 1 1 1
* 2 2
* 3
*/
public class UpperTriangularMatrix {
public static void main(String[] args) {
/*int matrix[][] = {
{1,1,1,1},
{2,2,2,2},
{3,3,3,3},
{4,4,4,4}
};
int rows = 4, columns = 4;*/
int matrix[][] = {
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4},
{5,5,5,5,5,5},
{6,6,6,6,6,6}
};
int rows = 6, columns = 6;
System.out.println("Upper Triangular Matrix is :");
for(int i=0;i<rows;i++){
for(int j=0;j<i;j++)
System.out.print(" ");
for(int j=i;j<columns;j++)
System.out.print(matrix[i][j]+" ");
System.out.println();
}
}
}
/*
OUTPUT
Upper Triangular Matrix is ::
1 1 1 1
2 2 2
3 3
4
OUTPUT
Upper Triangular Matrix is ::
1 1 1 1 1 1
2 2 2 2 2
3 3 3 3
4 4 4
5 5
6
*/