Answer:
Here is the JAVA program:
import java.util.Scanner; // to take input from user
public class VectorElementOperations {
public static void main(String[] args) {
final int NUM_VALS = 4; // size is fixed that is 4 and assigned to NUM_VALS
int[] origList = new int[NUM_VALS];
int[] offsetAmount = new int[NUM_VALS];
int i;
//two lists origList[] and offsetAmount[] are assigned values
origList[0] = 20;
origList[1] = 30;
origList[2] = 40;
origList[3] = 50;
offsetAmount[0] = 4;
offsetAmount[1] = 6;
offsetAmount[2] = 2;
offsetAmount[3] = 8;
String product=""; // product variable to store the product of 2 lists
for(i = 0; i <= origList.length - 1; i++){
/* loop starts with i at 0th position or index and ends when the end of the origList is reached */
/* multiples each element of origList to corresponding element of offsetAmount and stores result in the form of character string in product*/
product+= Integer.toString(origList[i] *= offsetAmount[i]) + " "; }
System.out.println(product); }} //displays the product of both lists
Output:
80 180 80 400
Explanation:
If you want to print the product of origList with corresponding value in offsetAmount in vertical form you can do this in the following way:
import java.util.Scanner;
public class VectorElementOperations {
public static void main(String[] args) {
final int NUM_VALS = 4;
int[] origList = new int[NUM_VALS];
int[] offsetAmount = new int[NUM_VALS];
int i;
origList[0] = 20;
origList[1] = 30;
origList[2] = 40;
origList[3] = 50;
offsetAmount[0] = 4;
offsetAmount[1] = 6;
offsetAmount[2] = 2;
offsetAmount[3] = 8;
for(i = 0; i <= origList.length - 1; i++){
origList[i] *= offsetAmount[i];
System.out.println(origList[i]); } }}
Output:
80
180
80
400
The program along with the output is attached as screenshot with the input given in the example.