fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static int[][] rotateImage(int[][] a)
  11. {
  12. int n = a.length;
  13. System.out.println("length" +n);
  14. for (int i = 0; i < n / 2; i++) {
  15. for (int j = 0; j < Math.ceil(((double) n) / 2.); j++) {
  16. int temp = a[i][j];
  17. a[i][j] = a[n-1-j][i];
  18. a[n-1-j][i] = a[n-1-i][n-1-j];
  19. a[n-1-i][n-1-j] = a[j][n-1-i];
  20. a[j][n-1-i] = temp;
  21. }
  22. }
  23. return a;
  24. }
  25.  
  26. public static void main (String[] args) throws java.lang.Exception
  27. {
  28. // your code goes here
  29. int a[ ][ ] = { {1,2,3} , {4,5,6},{7,8,9} };
  30. rotateImage(a);
  31. for(int i=0;i<3;i++){
  32. System.out.println();
  33. for(int j=0;j<3;j++)
  34. {
  35. System.out.print(a[i][j]);
  36. }
  37. }
  38. }
  39. }
Success #stdin #stdout 0.05s 4386816KB
stdin
Standard input is empty
stdout
length3

741
852
963