Created
November 3, 2015 20:02
-
-
Save edinak1/3e0a80f2cecce05d79af to your computer and use it in GitHub Desktop.
Copy.java
This file contains 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