// Program on copyOf and copyOfRange methods
import java.util.Arrays;
public class cp
{
public static void main(String args[])
{
int a[] = {2, 8, 6, 1, 4, 3};
int n = a.length;
for (int i=0; i<n; i++)
System.out.print(a[i]+" ");
System.out.println();
int[] c = Arrays.copyOf(a,5);
for (int i=0; i<c.length; i++)
System.out.println(a[i]+" ");
System.out.println();
int[] d = Arrays.copyOfRange(a,0, 3);
for (int i=0; i<d.length; i++)
System.out.println(a[i]+" ");
}
}
output:
import java.util.Arrays;
public class cp
{
public static void main(String args[])
{
int a[] = {2, 8, 6, 1, 4, 3};
int n = a.length;
for (int i=0; i<n; i++)
System.out.print(a[i]+" ");
System.out.println();
int[] c = Arrays.copyOf(a,5);
for (int i=0; i<c.length; i++)
System.out.println(a[i]+" ");
System.out.println();
int[] d = Arrays.copyOfRange(a,0, 3);
for (int i=0; i<d.length; i++)
System.out.println(a[i]+" ");
}
}
output:
No comments:
Post a Comment