Created
January 12, 2016 10:29
-
-
Save Yur-ok/6826c85692f80d5fc31e 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.KeyPoint5; | |
import java.util.Arrays; | |
/** | |
* Created by Юрий on 08.01.2016. | |
*/ | |
public class CopyArray { | |
public static void main(String[] args) { | |
int[] one = {1, 2, 9, 33, 44}; | |
int[] two = {4, 5, 6}; | |
copyArray(one, 0, two, 0, 2); | |
} | |
static void copyArray(int[] src, int srcPos, int[] dest, int destPos, int length) { | |
int restDest = dest.length - (destPos + length); | |
if (restDest < 0) { | |
System.out.println(-1); | |
} else { | |
for (int i = srcPos, k = destPos; length > 0; i++, k++) { | |
dest[k] = src[i]; | |
length--; | |
} | |
System.out.println(Arrays.toString(dest)); | |
} | |
} | |
} |
liuiv15
commented
Jan 21, 2016
- Если один из массивов null, будет ошибка.
- если параметры srcPos, dest, length будет отрицательным, будет ошибка.
- если сумма (srcPos+length) выйдет за границы массива, будет ошибка
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment