Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nomor1;
- public class Nomor1
- {
- public static void main(String[] args)
- {
- int[][] arr = {{1,1,1,1}, {0,1,6,6}, {0,0,7,7}, {0,0,0,5}};
- int countZero = 0;
- int countRow = 0;
- //Print array
- for(int i=0;i<arr.length;i++)
- {
- for(int j=0;j<arr[0].length;j++)
- {
- System.out.print(arr[i][j] + " ");
- }
- System.out.println();
- }
- //Check if matrix is upper triangular matrix
- for(int i=0;i<arr.length;i++)
- {
- for(int j=0;j<arr[0].length;j++)
- {
- if(i == 0)
- {
- if(arr[i][j] == 0)
- {
- countRow++;
- }
- } else
- {
- if(j < i-1)
- {
- if(arr[i][j] == 0)
- {
- countZero++;
- } else
- {
- countRow++;
- }
- } else
- {
- if(arr[i][j] == 0)
- {
- countRow++;
- }
- }
- }
- }
- if(i > 0)
- {
- if(countZero == i)
- {
- countRow++;
- }
- }
- countZero = 0;
- }
- if(countRow == arr.length-1)
- {
- System.out.println("Matrix segitiga atas");
- } else
- {
- System.out.println("Bukan matrix segitiga atas");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement