public static void main(String[] args) {
    int[][] a =
        new int[][] { { 1, 2, 3, 4, 5 }, { 6, 7, 8, 9, 10 }, { 11, 12, 13, 14, 15 },
            { 16, 17, 18, 19, 20 }, { 21, 22, 23, 24, 25 } };

    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        System.out.print(a[i][j] + "\t");
      }
      System.out.println();
    }
    System.out.println("---------------------");
    rotate1(a, 5);
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        System.out.print(a[i][j] + "\t");
      }
      System.out.println();
    }

    System.out.println("---------------------");

    a = new int[][] { { 1, 2, 3, 4 }, { 5, 6, 7, 8, }, { 9, 10, 11, 12 }, { 13, 14, 15, 16 } };

    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        System.out.print(a[i][j] + "\t");
      }
      System.out.println();
    }
    System.out.println("---------------------");
    rotate1(a, 4);
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        System.out.print(a[i][j] + "\t");
      }
      System.out.println();
    }

    System.out.println("---------------------");
  }