4
answers
0
watching
689
views
15 Jan 2018

16. The following method takes two integer arrays and a target integer as input. It is supposed to return true if there is an element from the first array and an element from the second array whose sum is the target integer. For instance, given arrays a=[1,4,3] and b=[2,6,3] and target 7, the method should return true because a[1]+b[2] = 4+3 = 7. However, if the target is 8, it should return false, as no element in array a, added with an element of array b results in 8. What should be the body of this method? public static boolean foo (int[] a, int[] b, int target) // What should go here? (A) for (int i = 0; i < a.length + b.length; i++) if(a[i] + b[i] == target) return true; else return false; (B) for (int i = 0; i

For unlimited access to Homework Help, a Homework+ subscription is required.

Unlock all answers

Get 1 free homework help answer.
Already have an account? Log in
Already have an account? Log in
Already have an account? Log in
Collen Von
Collen VonLv2
17 Jan 2018
Already have an account? Log in

Related Documents

Weekly leaderboard

Start filling in the gaps now
Log in