Advertisement
hpilo

Chapter6_Func_Ex7

Dec 15th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. /*
  2. =====================================================
  3. chapter 6: Functions
  4.  
  5. Ex7:
  6. =====================================================
  7. */
  8.  
  9. public class MyProgram {
  10. public static boolean isMirror(int matrix[][]){
  11. int rows=matrix.length;
  12. int cols=matrix[0].length;
  13.  
  14. for(int i=0;i<rows;i++){
  15. for(int j=0,k=cols-1;j<cols;j++,k--){
  16. if(matrix[i][j]!=matrix[i][k])
  17. return false;
  18. }
  19. }
  20. return true;
  21. }
  22.  
  23. public static void main(String[] args) {
  24. boolean res;
  25. int matrix1[][]={{2,1,5,1,2},{6,7,3,7,6},{0,8,0,8,0}};
  26. int matrix2[][]={{2,1,5,5,1,2},{6,7,3,3,7,6},{0,8,0,0,8,0}};
  27. int matrix3[][]={{2,1,5,1,2},{6,7,3,8,6},{0,8,0,8,0}};
  28.  
  29. res=isMirror(matrix1);
  30. System.out.println("matrix 1: "+res);
  31.  
  32. res=isMirror(matrix2);
  33. System.out.println("matrix 2: "+res);
  34.  
  35. res=isMirror(matrix3);
  36. System.out.println("matrix 3: "+res);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement