Question
Write a program to store 6 element in an array P, and 4 elements in an array Q and produce a third array R, containing all elements of array P and Q. Display the resultant array .
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
import java.util.Scanner;
public class program8
{
public static void main(String[] args)
{
int i=0;
Scanner sc = new Scanner(System.in);
int[] p = new int[6];
int[] q = new int[4];
int[] r = new int[10];
System.out.print("Enter 6 elements in array P: ");
for (i = 0; i < 6; i++)
{
p[i] = sc.nextInt();
}
System.out.print("Enter 4 elements in array Q: ");
for (i = 0; i < 4; i++)
{
q[i] = sc.nextInt();
}
for (i = 0; i < 6; i++)
{
r[i] = p[i];
}
for (i = 0; i < 4; i++)
{
r[i + 6] = q[i];
}
System.out.print("Elements of array R: ");
for (i = 0; i < 10; i++)
{
System.out.println(r[i]);
}
}
}