Answer:
In Java:
import java.util.*;
public class MyClass{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Length of array 1: ");
int lent1 = input.nextInt();
while(lent1 <= 0 || lent1 > 50){
System.out.print("Length of array 1: ");
lent1 = input.nextInt();
}
int[] array1 = new int[lent1];
System.out.print("Length of array 2: ");
int lent2 = input.nextInt();
while(lent2 <= 0 || lent2 > 50){
System.out.print("Length of array 2: ");
lent2 = input.nextInt();
}
int[] array2 = new int[lent2];
for(int i =0;i<lent1;i++){
array1[i] = (int)(Math.random() * (lent1*2) + 1);
}
for(int i =0;i<lent2;i++){
array2[i] = (int)(Math.random() * (lent2*2) + 1);
}
System.out.print("Array 1: ");
for(int i =0;i<lent1;i++){
System.out.print(array1[i]+" ");
}
System.out.println("Array 2: ");
for(int i =0;i<lent2;i++){
System.out.print(array2[i]+" ");
}
}
}
Explanation:
This prompts the user for length of the first array
System.out.print("Length of array 1: ");
This declares and gets input for the length of the first array
int lent1 = input.nextInt();
This validates the length of first array
<em> while(lent1 <= 0 || lent1 > 50){</em>
<em> System.out.print("Length of array 1: ");</em>
<em> lent1 = input.nextInt(); }</em>
This declares the first array
int[] array1 = new int[lent1];
This prompts the user for length of the second array
System.out.print("Length of array 2: ");
This declares and gets input for the length of the second array
int lent2 = input.nextInt();
This validates the length of the second array
<em> while(lent2 <= 0 || lent2 > 50){</em>
<em> System.out.print("Length of array 2: ");</em>
<em> lent2 = input.nextInt(); }</em>
This declares the second array
int[] array2 = new int[lent2];
The following generates random integers between 1 and lent1*2 to array 1
<em> for(int i =0;i<lent1;i++){</em>
<em> array1[i] = (int)(Math.random() * (lent1*2) + 1); }</em>
The following generates random integers between 1 and lent2*2 to array 2
<em> for(int i =0;i<lent2;i++){</em>
<em> array2[i] = (int)(Math.random() * (lent2*2) + 1); }</em>
This prints the header Array 1
System.out.print("Array 1: ");
The following iteration prints the content of the first array
<em> for(int i =0;i<lent1;i++){</em>
<em> System.out.print(array1[i]+" ");</em>
<em> }</em>
This prints the header Array 2
System.out.println("Array 2: ");
The following iteration prints the content of the second array
<em> for(int i =0;i<lent2;i++){</em>
<em> System.out.print(array2[i]+" ");</em>
<em> }</em>
<em />