Skip to content

Instantly share code, notes, and snippets.

@AnnaBoro
Created September 24, 2015 20:27
Show Gist options
  • Save AnnaBoro/4161c6de9e8135e08b1b to your computer and use it in GitHub Desktop.
Save AnnaBoro/4161c6de9e8135e08b1b to your computer and use it in GitHub Desktop.
package lesson3;
import java.util.Arrays;
public class Homework2 {
public static void main(String[] args) {
int[] arr = {0, 1, 2};
int[] arr2 = new int[2];
System.out.println("arr " + Arrays.toString(arr) + " arr2 " + Arrays.toString(arr2));
copyArray(arr, 0, arr2, 0, 2);
System.out.println("arr " + Arrays.toString(arr) + " arr2 " + Arrays.toString(arr2));
}
static void copyArray(int[] src, int srcPos, int[] dest, int destPos, int length) {
if (src != null && dest != null && srcPos < src.length && destPos < dest.length) {
for (int i = srcPos, j = destPos; i < length; i++, j++) {
dest[j] = src[i];
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment