Given an integer array A of size N. You have to construct a new B array with a length of (N+N). For each index i from 0 to N-1, the value of B[i] should be same as the value of A[i], and the value of B[i+N] should also be same as value of A[i].
In simple terms, you have to duplicate the A array and place them consecutively in the B array two times.
Input Format
First line of input contains N – size of the array A. The next line contains N integers of array A.
Constraints
1 <= N <= 1000
1 <= A[i] <= 1000
Output Format
Print the elements of the B array separated by space.
Input | Output |
---|---|
3 6 7 7 | 6 7 7 6 7 7 |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = sc.nextInt();
}
int[] B = new int[2 * N];
for (int i = 0; i < N; i++) {
B[i] = A[i];
}
for (int i = 0; i < N; i++) {
B[i + N] = A[i];
}
for (int i = 0; i < 2 * N; i++) {
System.out.print(B[i] + " ");
}
}
}