-
Notifications
You must be signed in to change notification settings - Fork 153
/
rotateTile.java
60 lines (59 loc) · 1.46 KB
/
rotateTile.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;
/**
* @date 3/02/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class rotateTile {
public static int[][] rotate(int arr[][])
{
int i,j,ri=0;
int rj=arr.length-1;
int rot[][]=new int[arr.length][arr.length];
for(i=0;i<arr.length;i++)
{
for(j=0;j<arr.length;j++)
{
rot[ri][rj]=arr[i][j];
ri++;
}
rj--; ri=0;
}
return rot;
}
public static void main(String []args)
{
int n,i,j;
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
int ri=0,rj=n-1;
int arr[][]=new int[n][n];
for(i=0;i<n;i++)
for(j=0;j<n;j++)
arr[i][j]=sc.nextInt();
System.out.println("Original matrix is ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();
}
int rot[][]=rotate(arr);
System.out.println("Rotated matrix is ");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
System.out.print(rot[i][j]+" ");
}
System.out.println();
}
}
}