Question: java Instructions In this problem, you will be given an integer n, followed by two integer arrays of length n. You will check to see



Instructions In this problem, you will be given an integer n, followed by two integer arrays of length n. You will check to see if the values in the second array are exactly the sum of those in the first array plus 17 You will look through each of the array indices to see if they add up. The first set of atray elements you reach that do not add up" you will output: * + 17 = y(not x) where is the value in the first array, zis the value in the second and is the expected sum fie ywx+17) eg. Assume you are passed the integer 3 and the arrays (2,1,5) and (19.21.22), each of length 3. You would check that +17-19. which possess our test. However, the next poir 1 from the first array and 21 from the second array) does not as 1+17 does not equal 21. Thus, the program would output 1 + 17 - 18 (not 21) Write the portion of the program that reads the input into the arrays (firstArray and sumrray) Function Details Input (THIS IS YOUR TASKI The program reads in one integer n, followed by two integer arrays (array/ and way of longth a Processing This was handled for you For each element xin arayl, check whether or not the respective element in array2 is the sum of x and 17. That is, check whether or not ywx+12 if the sums match, move on to the next element. It an error is found output as follows Output Output is also handled for you It all sums match. Output it all adds up". Otherwise, at the first sum error found output the following: * + 17 =y (not z) where x is the value from arrayt, z is the value from array and is the sum that would be expected Sample input/output: Sample Input Sample Output 221 19 18 It all adds up 3 21 5 19 21 22 1 + 17 - 18 (not 21) 2 23 39 10 23. 17-40 tot 391 import java.util.*; public class POD { public static void main(String[] args) { //Instantiate new scanner to read from the console. Scanner in = new Scanner(System.in); //Declare & initialize variables int n = in.nextInt(); int[] firstArray = new int[n]; int[] sumArray = new int[n]; boolean sumsMatch true; int sum = 0; //PLEASE START YOUR WORK HERE //Read input into first array //Read input into second array //PLEASE END YOUR WORK HERE V/PLEASE END YOUR WORK HERE V/Output 7/Output int i sum while (sumsMatch && j n) { firstArray[j] + 17; if (sum != sumArray[j]) { sumsMatch = false; System.out.println(firstArray[j] } + 17 - " + sum + (not sumArray[j] +")"); } if (sumsMatch){ System.out.println("It all adds up"); } System.out.print("END OF OUTPUT"); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
