Created
December 30, 2015 07:32
-
-
Save Yur-ok/74671ff8bd7fb9266d24 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package Lesson3.KeyPoint3; | |
| import java.util.Arrays; | |
| /** | |
| * Created by Юрий on 30.12.2015. | |
| */ | |
| public class Union { | |
| static int[] union(int[] data1, int[] data2) { | |
| int len1 = data1.length; | |
| int len2 = data2.length; | |
| int[] sumData = new int[len1 + len2]; | |
| int count = 0; | |
| if (count < data1.length) { | |
| for (int i : data1) { | |
| sumData[count] = i; | |
| count++; | |
| } | |
| } | |
| if (count == data2.length) { | |
| for (int i : data2) { | |
| sumData[count] = i; | |
| count++; | |
| } | |
| } | |
| return sumData; | |
| } | |
| public static void main(String[] args) { | |
| int[] arr1 = {5, 4, 3}; | |
| int[] arr2 = {9, 7, 6}; | |
| System.out.println(Arrays.toString(union(arr1, arr2))); | |
| } | |
| } |
Эх! Точно!
Второй if был лишним, вообще не пойму зачем я эту проверку сделал. Видимо заработался, когда писал этот код.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ваша программа работает только, если размерности объединяемых массивов одинаковые.