Answered step by step
Verified Expert Solution
Question
1 Approved Answer
POD 1 Instructions In this problem, you will be given an integer n , followed by two integer arrays of length n . You will
POD 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
You will look through each of the array indices to see if they "add up The first set of array elements you reach that do not "add up you will output:
x y not z
where x is the value in the first array, z is the value in the second and y is the expected sum ie yx
eg Assume you are passed the integer and the arrays and each of length You would check that which passess our test. However, the next pair from the first array and from the second array does not as does not equal Thus, the program would output
not
Write the portion of the program that reads the input into the arrays firstArray and sumArray
Function Details
Input
THIS IS YOUR TASK!
The program reads in one integer n followed by two integer arrays array and array of length n
Processing
This was handled for you.
For each element x in array check whether or not the respective element y in array is the sum of x and That is check whether or not yx If the sums match, move on to the next element. If an error is found, output as follows.
Output
Output is also handled for you.
If all sums match, output It all adds up Otherwise, at the first sum error found, output the following:
x y not z
where x is the value from array z is the value from array and y is the sum that would be expected.
import java.util.;
public class PoD
public static void mainString args
Instantiate new scaSample inputoutput:nner to read from the console.
Scanner in new Scanner System.in ;
Declare & initialize variables
int n innextInt;
int firstArray new intn;
int sumArray new intn;
boolean sumsMatch true;
int sum ;
PLEASE START YOUR WORK HERE
WRITE YOUR CODE HERE
PLEASE END YOUR WORK HERE
Output
int j ;
while sumsMatch && j
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started