From e72d71c0d7288afe583af4aab612361bd31c820a Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 20 Sep 2021 18:50:09 +0000 Subject: [PATCH] Formatted with Google Java Formatter --- Others/RotateMatriceBy90Degree.java | 93 +++++++++++++---------------- 1 file changed, 41 insertions(+), 52 deletions(-) diff --git a/Others/RotateMatriceBy90Degree.java b/Others/RotateMatriceBy90Degree.java index 53cc3c54..1c5419a3 100644 --- a/Others/RotateMatriceBy90Degree.java +++ b/Others/RotateMatriceBy90Degree.java @@ -1,71 +1,60 @@ package Others; /** - * Given a matrix of size n x n - * We have to rotate this matrix by 90 Degree - * Here is the algorithm for this problem . - * + * Given a matrix of size n x n We have to rotate this matrix by 90 Degree Here is the algorithm for + * this problem . */ - import java.util.*; class Rotate_by_90_degree { - public static void main(String[] args) { - Scanner sc = new Scanner(System.in); - int t = sc.nextInt(); + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int t = sc.nextInt(); - while (t-- > 0) { - int n = sc.nextInt(); - int[][] arr = new int[n][n]; + while (t-- > 0) { + int n = sc.nextInt(); + int[][] arr = new int[n][n]; - for (int i = 0; i < n; i++) - for (int j = 0; j < n; j++) - arr[i][j] = sc.nextInt(); + for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) arr[i][j] = sc.nextInt(); - Rotate g = new Rotate(); - g.rotate(arr); - printMatrix(arr); - - } - sc.close(); + Rotate g = new Rotate(); + g.rotate(arr); + printMatrix(arr); } + sc.close(); + } - static void printMatrix(int arr[][]) { - for (int i = 0; i < arr.length; i++) { - for (int j = 0; j < arr[0].length; j++) - System.out.print(arr[i][j] + " "); - System.out.println(""); - } + static void printMatrix(int arr[][]) { + for (int i = 0; i < arr.length; i++) { + for (int j = 0; j < arr[0].length; j++) System.out.print(arr[i][j] + " "); + System.out.println(""); } + } } -/** - * Class containing the algo to roate matrix by 90 degree - */ - +/** Class containing the algo to roate matrix by 90 degree */ class Rotate { - static void rotate(int a[][]) { - int n = a.length; - for (int i = 0; i < n; i++) { - for (int j = 0; j < n; j++) { - if (i > j) { - int temp = a[i][j]; - a[i][j] = a[j][i]; - a[j][i] = temp; - } - } + static void rotate(int a[][]) { + int n = a.length; + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + if (i > j) { + int temp = a[i][j]; + a[i][j] = a[j][i]; + a[j][i] = temp; } - int i = 0, k = n - 1; - while (i < k) { - for (int j = 0; j < n; j++) { - int temp = a[i][j]; - a[i][j] = a[k][j]; - a[k][j] = temp; - } - - i++; - k--; - } - + } } + int i = 0, k = n - 1; + while (i < k) { + for (int j = 0; j < n; j++) { + int temp = a[i][j]; + a[i][j] = a[k][j]; + a[k][j] = temp; + } + + i++; + k--; + } + } }