There are two lists of numbers. Create a resultant list whose elements are the product of
the elements of the two lists.
Example: List A List B List C
21 30 630
50 10 500
.... .... ....
Write a Java program using a one-dimensional array that accepts as input an integer
value asking for the number of elements for each list. This will be used to generate random
numbers (5 to 69) for the one-dimensional arrays (List A and List B). The program will
compute for the product and store it in another array (List C). Display the result similar to
the Example above.
import java.util.Random;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
Random random = new Random();
System.out.println("Size:");
int size = in.nextInt();
int[] a = new int[size];
int[] b = new int[size];
int[] c = new int[size];
System.out.println("List A List B List C");
for (int i = 0; i < size; i++) {
a[i] = random.nextInt(65) + 5;
b[i] = random.nextInt(65) + 5;
c[i] = a[i] * b[i];
System.out.println(a[i] + " " + b[i] + " " + c[i]);
}
}
}
Comments
Leave a comment