Multiply each element in origList with the corresponding value in offsetAmount. Print each product followed by a space.Ex: If origList = {4, 5, 10, 12} and offsetAmount = {2, 4, 7, 3}, print:8 20 70 36 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;/* Your solution goes here */System.out.println("");}}

Respuesta :

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.

Ver imagen mahamnasir
Ver imagen mahamnasir

Answer:

int main() {

const int NUM_VALS = 4;

int origList[NUM_VALS];

int offsetAmount[NUM_VALS];

int i;

cin >> origList[0] = 20;

cin >> origList[1] = 30;

cin >> origList[2] = 40;

cin >> origList[3] = 50;

cin >> offsetAmount[0] = 5;

cin >> offsetAmount[1] = 7;

cin >> offsetAmount[2] = 3;

cin >> offsetAmount[3] = 4;

for(i = 0; i < origList[i] - 1; i++){

origList[i] *= offsetAmount[i];

cout << origList[i]<< " ";

}

cout << endl;

return 0;

}

Explanation: set i = 0. i is less than i -1, so it will always move to the next value in the array. The *= operator multiplies the expression to the right by the variable on the left, then assigns the result to the variable. This means that origList[0] *= offsetAmount[0] will assign

origList[0] with 100 and so on.