Question: Please follow the instructions in image 2 This program should print out all common elements of two given arrays Two testing arrays a and b
This program should print out all common elements of two given arrays Two testing arrays a and b are created at the beginning of the program Your first task is to create two methods at test them: printMyArray (int [] arr) and hasElement(int [] arr, int x) printMyArray() should simply print out all elements of the given array hasElement, takes and array of integers arr and an integer number x as inputs and returns true if arr has even one element equal to x. Otherwise it should return false. Your next task is to finish the main: 1. Print out given arrays a and b using printArray method 2. In a loop, use method hasElement() to check if any element of a is contained in b. If it is, print out that this element is a common element. Your output should look like this: Array a: 1 2 34 5 12 Array b: 2 56712 Common element:2 Common element: 5 Common element: 12
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
