-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRot90.java
More file actions
67 lines (56 loc) · 2.26 KB
/
Rot90.java
File metadata and controls
67 lines (56 loc) · 2.26 KB
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
61
62
63
64
65
66
import java.util.*;
public class Rot90//start of class
{
int temp;
public static void main (String args[]) {// start of main method
Scanner sc = new Scanner(System.in);
System.out.println("please enter size");
int s = sc.nextInt();//obtaining input for size of array
int arr[][]= new int[s][s];//initialising the array
System.out.println("please enter data");
for(int i=0;i<s;i++) {//starting a for loop
for(int j=0;j<s;j++) {//starting a nested for loop
arr[i][j] = sc.nextInt();//inputting data to an arra
}//ending a nested for loop
}//ending a for loop
for(int i=0;i<s;i++) {//starting a for loop
for(int j=0;j<s;j++) {//starting a nested for loop
System.out.print(arr[i][j]+"\t");//printing a column of array
}//ending a nested for loop
System.out.println();//breaking a line
}
for(int i=0;i<s;i++) {//starting a for loop
for(int j=0;j<s;j++) {//starting a nested for loop
int temp= arr[i][j];//swapping
arr[i][j]=arr[j][i];
arr[j][i]= temp;
}//ending a nested for loop
System.out.println("Rotated Matrix");
for(i=0;i<s;i++) {//starting a nested for loop
for(int j=0;j<s;j++) {//starting a nested for loop
System.out.print(arr[i][j]+"\t");//printing a column of array
}//ending a nested for loop
System.out.println();//breaking a line
}//ending a nested for loop
}//ending a for loop
}//end of main method
}//end of class
/* Variable Description Table
* Variable Type Description
* s int to store the size of 2d array
* arr[][] int an integer array
* i int used in for loop
* j int used in for loop
* temp int temporary variable used swapping
*/
/*
👋 Hi, I’m @aarushinair — Aarushi Nair (she/her)
🎓 CS Engineer | AI Researcher | Software Engineer | DEI Professional
💡 Interests: AI/ML/DL, Responsible Tech, Innovative Technologies, Ethics in AI
🌍 Advocate for Women in Tech | Community & Events Manager @AnitaB.org India
🎙️ Speaker | Content Creator | STEM Mentor
📫 Let’s connect: https://www.linkedin.com/in/aarushinair/
📹 YouTube: Code with Aarushi → https://www.youtube.com/channel/UCKj5T1ELHCmkGKujkpqtl7Q
🐦 Twitter/X: https://x.com/aarushinair_
📁 Portfolio, projects & talks: https://github.com/aarushinair
*/