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
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
22 Jun 2023
gloryolalere280Lv10
20 Nov 2022
Already have an account? Log in
3 Mar 2022
Already have an account? Log in
Collen VonLv2
17 Jan 2018
Already have an account? Log in