Answered step by step
Verified Expert Solution
Link Copied!

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 1Instructions
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 array elements you reach that do not "add up", you will output:
x +17= 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 (i.e. y=x+17).
e.g. 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 2+17=19, which passess our test. However, the next pair (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 sumArray).
Function Details
Input
[THIS IS YOUR TASK!]
The program reads in one integer n, followed by two integer arrays (array1 and array2) of length n.
Processing
This was handled for you.
For each element x in array1, check whether or not the respective element y in array2 is the sum of x and 17. That is, check whether or not y=x+17. 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 +17= y (not z)
where x is the value from array1, z is the value from array2 and y is the sum that would be expected.
import java.util.*;
public class PoD {
public static void main(String[] args){
//Instantiate new scaSample input/output:nner 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
// WRITE YOUR CODE HERE
//PLEASE END YOUR WORK HERE
//Output
int j =0;
while (sumsMatch && j
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions

Question

=+Does it present new cocktails or review restaurants?

Answered: 1 week ago

Question

=+Is the message on-strategy?

Answered: 1 week ago