In Built Function of Array
System.arraycopy(a,i,b,j,n);
a-The array which is to be copied
i- The array index from which copying is started
b-The array in which to be copied
j-The array index to which pasting is started
n-The number of elements to be copied
arrayname.length - calculates the length of array
import java.util.*;
class ArrayFunctionDemo
{
public static void main(String args[])
{
//array declaration is done by using <data type> array_name
//array initialization is done at run time using new keyword
int marks[] = new int[4];
Scanner mark = new Scanner(System.in);//Scanner is inbuilt class
System.out.println("ENTER THE MARKS: ");
for(int i=0;i<marks.length;i++)
{
marks[i]=mark.nextInt();//here nextInt is inbuilt method to enter the integer value from user
}
System.out.println("THE MARKS IS:");
//enhanced for loop
for(int x:marks)//or we can write it as: for(int x=0;x<marks.length;x++)
{
System.out.println(x);//here we can also write that System.out.println(marks[]);
}
int arr[]={1,2,3,4,5};//direct initializatio of array
//arraycopy() is the method to copy the one array contents with another using System.arraycopy( , , , , );
System.arraycopy(marks,1,arr,0,2);
for(int m:arr)
{
System.out.println(m);
}
}
}
No comments:
Post a Comment