Created
September 24, 2015 20:27
-
-
Save AnnaBoro/4161c6de9e8135e08b1b 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; | |
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