-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsuffle.java
More file actions
43 lines (34 loc) · 1.07 KB
/
Copy pathsuffle.java
File metadata and controls
43 lines (34 loc) · 1.07 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
import java.util.Scanner;
public class suffle {
public int[] shuffle(int[] nums, int n) {
int[] arr = new int[2 * n];
for (int i = 0; i < n; i++) {
arr[2 * i] = nums[i];
arr[2 * i + 1] = nums[i + n];
}
return arr;
}
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number of elements (even number): ");
int a = input.nextInt();
if (a % 2 != 0) {
System.out.println("Number of elements must be even.");
input.close();
return;
}
int[] nums = new int[a];
System.out.println("Enter elements for nums array:");
for (int i = 0; i < a; i++) {
nums[i] = input.nextInt();
}
int n = a / 2;
suffle solution = new suffle();
int[] result = solution.shuffle(nums, n);
System.out.print("Shuffled Array: ");
for (int value : result) {
System.out.print(value + " ");
}
input.close();
}
}