Store Six Random characters in Array & copy 2 to 4 index values to another Array with same index in JAVA
CODING:
import java.util.Arrays;
import java.util.Random;
class CopyArry
{
public static void main(String[] args)
{
char[] a=new char[6];
Random r=new Random();
int i;
for(i=0;i<6;i++)
a[i]=(char)(97 + r.nextInt(26));
System.out.println("First Array...");
System.out.println(Arrays.toString(a));
char[] b =Arrays.copyOfRange(a,2,5);
System.out.println("Copy 2 to 4 Index,First Array To Second Array");
System.out.println(Arrays.toString(b));
}
}
import java.util.Random;
class CopyArry
{
public static void main(String[] args)
{
char[] a=new char[6];
Random r=new Random();
int i;
for(i=0;i<6;i++)
a[i]=(char)(97 + r.nextInt(26));
System.out.println("First Array...");
System.out.println(Arrays.toString(a));
char[] b =Arrays.copyOfRange(a,2,5);
System.out.println("Copy 2 to 4 Index,First Array To Second Array");
System.out.println(Arrays.toString(b));
}
}
Comments
Post a Comment