Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package nomor2;
- public class Nomor2
- {
- public static void main(String[] args)
- {
- int[][] arr = {{1,0,0,0}, {0,1,0,0}, {0,0,1,0}, {0,0,0,1}};
- int countOtherNum = 0;
- int countOne = 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 the matrix is identity matrix
- for(int i=0;i<arr.length;i++)
- {
- for(int j=0;j<arr[0].length;j++)
- {
- if(j != i)
- {
- if(arr[i][j] != 0)
- {
- countOtherNum++;
- }
- } else
- {
- if(arr[i][j] == 1)
- {
- countOne++;
- }
- }
- }
- }
- if(countOne == arr.length && countOtherNum == 0)
- {
- System.out.println("Matriks identitas");
- } else
- {
- System.out.println("Bukan matriks identitas");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement