-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcentration.java
More file actions
38 lines (29 loc) · 969 Bytes
/
Copy pathconcentration.java
File metadata and controls
38 lines (29 loc) · 969 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
import java.util.Scanner;
public class concentration {
public int[] getConcatenation(int[] nums) {
int n = nums.length;
int[] ans = new int[2 * n];
for (int i = 0; i < n; i++) {
ans[i] = nums[i];
ans[i + n] = nums[i];
}
return ans;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the size of the array: ");
int n = input.nextInt();
int[] num = new int[n];
System.out.println("Enter " + n + " integers:");
for (int i = 0; i < n; i++) {
num[i] = input.nextInt();
}
concentration solution = new concentration();
int[] result = solution.getConcatenation(num);
System.out.print("Concatenated array: ");
for (int val : result) {
System.out.print(val + " ");
}
input.close();
}
}