Answer to Question #299722 in Java | JSP | JSF for JEZ

Question #299722

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.


1
Expert's answer
2022-02-19T02:39:01-0500
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]);
        }

    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS