-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpperTriangularMatrix.java
33 lines (33 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
import java.util.Scanner;
public class UpperTrianglularMatrix {
static boolean isUpperTriangle(int square[][],int rowSize){
for(int row=1;row<rowSize;row++){
for(int col=0;col<row;col++){
if(square[row][col]!=0)
return false;
}
}
return true;
}
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int rowSize=sc.nextInt();
int colSize=sc.nextInt();
if(rowSize!=colSize || rowSize<=0){
System.out.println("Invalid Input");
}
else{
int square[][]=new int[rowSize][colSize];
for(int row=0;row<rowSize;row++){
for(int col=0;col<colSize;col++){
square[row][col]=sc.nextInt();
}
}
sc.close();
if(isUpperTriangle(square, rowSize))
System.out.println("Yes");
else
System.out.println("No");
}
}
}