-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReversePartOfArray.java
More file actions
39 lines (33 loc) · 919 Bytes
/
ReversePartOfArray.java
File metadata and controls
39 lines (33 loc) · 919 Bytes
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
import java.util.Scanner;
public class ReversePartOfArray {
public static void main(String[] args) {
/*
* Given an Array A[], starting index B and ending index C.Reverse an array from index B to index C.
*
* */
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int[] A = new int[N];
for(int i=0;i<N; i++){
A[i] = scanner.nextInt();
}
int B= 1; // starting index
int C= 3; // ending index
reversePartOfArray(A, B, C);
}
public static void reversePartOfArray(int[] A, int B, int C){
int temp = 0;
int i =B;
int j =C;
while (i< j){
temp = A[i];
A[i] = A[j];
A[j] = temp;
i++;
j--;
}
for(int k=0; k<A.length; k++){
System.out.println(A[k]);
}
}
}