Skip to content

Commit 0492cb5

Browse files
authored
Create ReverseArrayBySpecifiedPosition.java
1 parent 88bf708 commit 0492cb5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.Scanner;
2+
public class ReverseArrayBySpecifiedPosition{
3+
public static void main(String[] args){
4+
Scanner sc = new Scanner(System.in);
5+
6+
int n = sc.nextInt();
7+
int a[] = new int[n];
8+
int temp[] = new int[n];
9+
for(int i=0; i<n; i++){
10+
a[i]=sc.nextInt();
11+
}
12+
int index = sc.nextInt();
13+
for(int i=index-1; i>=0; i--){
14+
temp[i]=a[i];
15+
System.out.print(temp[i]+" ");
16+
}
17+
for(int i=index; i<n; i++){
18+
temp[i]=a[i];
19+
System.out.print(temp[i]+" ");
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)