Advertisement
Guest User

Nomor 1

a guest
Nov 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.79 KB | None | 0 0
  1. package nomor1;
  2.  
  3. public class Nomor1
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.         int[][] arr = {{1,1,1,1}, {0,1,6,6}, {0,0,7,7}, {0,0,0,5}};
  8.         int countZero = 0;
  9.         int countRow = 0;
  10.        
  11.         //Print array
  12.         for(int i=0;i<arr.length;i++)
  13.         {
  14.             for(int j=0;j<arr[0].length;j++)
  15.             {
  16.                 System.out.print(arr[i][j] + " ");
  17.             }
  18.          
  19.             System.out.println();
  20.         }
  21.        
  22.         //Check if matrix is upper triangular matrix
  23.         for(int i=0;i<arr.length;i++)
  24.         {
  25.             for(int j=0;j<arr[0].length;j++)
  26.             {
  27.                 if(i == 0)
  28.                 {
  29.                     if(arr[i][j] == 0)
  30.                     {
  31.                         countRow++;
  32.                     }
  33.                 } else
  34.                 {
  35.                     if(j < i-1)
  36.                     {
  37.                         if(arr[i][j] == 0)
  38.                         {
  39.                           countZero++;
  40.                         } else
  41.                         {
  42.                             countRow++;  
  43.                         }
  44.                     } else
  45.                     {
  46.                         if(arr[i][j] == 0)
  47.                         {
  48.                           countRow++;
  49.                         }
  50.                     }
  51.                 }
  52.             }
  53.            
  54.             if(i > 0)
  55.             {
  56.                 if(countZero == i)
  57.                 {
  58.                     countRow++;
  59.                 }
  60.             }
  61.            
  62.             countZero = 0;
  63.         }
  64.        
  65.         if(countRow == arr.length-1)
  66.         {
  67.             System.out.println("Matrix segitiga atas");
  68.         } else
  69.         {
  70.             System.out.println("Bukan matrix segitiga atas");
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement