-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.java
45 lines (39 loc) · 1.33 KB
/
Main.java
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
44
45
package com.yurii.salimov.lesson05.task04;
import java.util.Arrays;
import java.util.Random;
/**
* 5.4 Задача
*
* Написать ф-ю для объединения 2-х массивов в один. Вывести
* результат на консоль.
*
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
*/
public class Main {
public static void main(String[] args) {
final int length = 10;
final int[] first = randomNumbers(length);
final int[] second = randomNumbers(length);
final int[] result = concat(first, second);
print(first);
print(second);
print(result);
}
private static int[] concat(final int[] first, final int[] second) {
final int[] result = new int[first.length + second.length];
System.arraycopy(first, 0, result, 0, first.length);
System.arraycopy(second, 0, result, first.length, second.length);
return result;
}
private static int[] randomNumbers(final int length) {
final int[] numbers = new int[length];
final Random random = new Random();
for (int i = 0; i < length; i++) {
numbers[i] = random.nextInt(length);
}
return numbers;
}
private static void print(final int[] array) {
System.out.println(Arrays.toString(array));
}
}