Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package DZ5DZ6.HomeWork1StarArrays;
- /**
- * Created by Максим Беседа on 28.04.2016.
- */
- public class IdentityMatrixChecker {
- static boolean isIdentity(int[][] matrix){
- boolean identity = true;
- if (matrix.length != matrix[0].length){
- throw new IllegalArgumentException();
- }
- else {
- for (int i = 0; i < matrix.length; i++){
- for (int j = 0; j < matrix[0].length; j++){
- if ((i == j) && (matrix[i][j] != 1)){
- identity = false;
- }
- if ((i != j) && (matrix[i][j] != 0)){
- identity = false;
- }
- }
- }
- }
- return identity;
- }
- public static void main(String[] args) {
- System.out.println(isIdentity(new int[][]{{1, 0, 0},
- {0, 1, 0},
- {0, 0, 1}}));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement