-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateAndReverse.java
More file actions
71 lines (56 loc) · 2.17 KB
/
RotateAndReverse.java
File metadata and controls
71 lines (56 loc) · 2.17 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
67
68
69
70
71
/*Rotate array by one in clockwise direction and then reverse it*/
import java.util.Scanner;
import java.util.Arrays;
public class RotateAndReverse {
public static void main(String args[]) {
int[] arr;
int N, d, temp;
boolean flag = true;
int count = 1;
char ch = 'y';
Scanner scan = new Scanner(System.in);
while(count<201){
if (ch == 'y'){
System.out.println("Enter length of array:");
N = scan.nextInt();
d = (N-1);
arr = new int[N];
System.out.println("enter array elements one by one");
for (int i=0;i<N;i++){
arr[i] = scan.nextInt();
}
System.out.println("entered array");
System.out.println(Arrays.toString(arr));
for (int i=0;i<1;i++){
temp = arr[N-1];
for(int j=N-2;j>=0;j--){
arr[j+1] = arr[j];
}
arr[0] = temp;
}
System.out.println("Rotated Array");
System.out.println(Arrays.toString(arr));
for (int i=0;i<(N/2);i++){
temp = arr[i];
arr[i] = arr[d];
arr[d] = temp;
d = d - 1;
}
System.out.println("Reversed Array");
System.out.println(Arrays.toString(arr));
}
else{
flag = false;
break;
}
System.out.println("No. of test cases done: ");
System.out.println(count);
if (count == 199){
System.out.println("Last test case remaining");
}
count = count + 1;
System.out.println("Do you wish to continue?");
ch = scan.next().charAt(0);
}
}
}