For unlimited access to Homework Help, a Homework+ subscription is required.
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. Write a method removeNegatives which takes as input an array of int and returns a new array in which only the non-negative values are kept. For example, if the original array contains 10 -2 0 4 -1, your method should return an array of length 3 containing 10 0 4.
1. In each of the following you should write an expression or short piece of Javacode. (10 points) • Given a boolean bl and a boolean b2 write a boolean expression indicating whether at least one of them is true.