Created
June 25, 2018 00:50
-
-
Save LunaticWolf/ee8ef3d6e2e187d4e0704908189476ae to your computer and use it in GitHub Desktop.
CopyOf
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
import java.util.*; | |
import static java.lang.System.*; | |
public class CopyOf{ | |
public static int[] copyOf(int[] arr){ | |
int blah[] = new int[arr.length]; | |
for(int i = 0; i < arr.length; i++){ | |
blah[i] = arr[i]; | |
} | |
return blah; | |
} | |
public static void main(String[] args) { | |
Scanner s = new Scanner(in); | |
out.println("Enter the size of the array"); | |
int n = s.nextInt(); | |
int arr[] = new int[n]; | |
for(int i = 0; i < arr.length; i++) arr[i] = s.nextInt(); | |
int NewArray[] = copyOf(arr); | |
out.println("First Array"); | |
out.println(Arrays.toString(arr)); | |
out.println("Second Array"); | |
out.println(Arrays.toString(NewArray)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment