Created
November 3, 2015 20:03
-
-
Save edinak1/1dcf8d500a4ae1bca17a 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 test; | |
import java.util.Arrays; | |
public class Copy { | |
public static void main(String[] args) { | |
int []src={1,2,3}; | |
int []dest={0,7,9,8,34}; | |
copyArray(src,0,dest,0,3); | |
System.out.println(Arrays.toString(dest));; | |
} | |
static void copyArray(int[]src,int srcPos, int[]dest, int destPos,int length) | |
{ | |
if(src==null || dest == null || srcPos>src.length-1 || | |
src.length<length || dest.length<(destPos+length)) | |
{ | |
System.out.println("arguments not correct, arrays don't change"); | |
return; | |
} | |
for(int i=destPos;i<destPos+length;i++) | |
{ | |
dest[i]= src[srcPos++]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
А если случайно передать значение индексов отрицательными, что будет?