5.27 LAB: Sum of products (JAVA) Write a program in java that reads two lists of integers from input into two arrays and outputs the sum of multiplying the corresponding list items. The program first reads an integer representing the length of each list, followed by two lists of integers. Ex: If the input is: 3 1 2 3 3 2 1 the program calculates (1 * 3) + (2 * 2) + (3 * 1) and outputs 10 Ex: If the input is: 4 2 3 4 5 1 1 1 1 the program calculates (2 * 1) + (3 * 1) + (4 * 1) + (5 * 1) and outputs 14 Code starts here: import java.util.Scanner; public class LabProgram { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int size; size = scnr.nextInt(); int[] listA = new int[size]; // List A int[] listB = new int[size]; // List B /* Type your code here. */ } }
5.27 LAB: Sum of products (JAVA)
Write a
Ex: If the input is:
3 1 2 3 3 2 1the program calculates (1 * 3) + (2 * 2) + (3 * 1) and outputs
10Ex: If the input is:
4 2 3 4 5 1 1 1 1the program calculates (2 * 1) + (3 * 1) + (4 * 1) + (5 * 1) and outputs
14import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
int size;
size = scnr.nextInt();
int[] listA = new int[size]; // List A
int[] listB = new int[size]; // List B
/* Type your code here. */
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images