Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. package DZ5DZ6.HomeWork1StarArrays;
  2.  
  3. /**
  4. * Created by Максим Беседа on 28.04.2016.
  5. */
  6. public class IdentityMatrixChecker {
  7. static boolean isIdentity(int[][] matrix){
  8. boolean identity = true;
  9. if (matrix.length != matrix[0].length){
  10. throw new IllegalArgumentException();
  11. }
  12. else {
  13. for (int i = 0; i < matrix.length; i++){
  14. for (int j = 0; j < matrix[0].length; j++){
  15. if ((i == j) && (matrix[i][j] != 1)){
  16. identity = false;
  17. }
  18. if ((i != j) && (matrix[i][j] != 0)){
  19. identity = false;
  20. }
  21. }
  22. }
  23. }
  24. return identity;
  25. }
  26.  
  27. public static void main(String[] args) {
  28. System.out.println(isIdentity(new int[][]{{1, 0, 0},
  29. {0, 1, 0},
  30. {0, 0, 1}}));
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement