Write a short Java method that takes an array of int values and determines if there is a pair of distinct elements of the array whose product is even.
// java program to check if there is a pair of distinct elements of the array whose product is even. package java_problems_datastructures; public class CheckForEvenProduct { // initilizing the array static int[] arrayOfIntegers = {32, 54, 3, 8, 787, 45, 1, 4, 9, 7 }; public boolean doesItContainsEvenProduct(int[] arr) { // set boolean value to false first boolean isEvenProduct = false; for (int i = 0; i < arr.length; i++) { for (int j = 1; j < arr.length; j++) { // logic is both should be distinct and there shouldn't be any reminder // we implemented that logic below if (arr[j] != arr[i] && ((arr[j] * arr[i]) % 2 == 0)) isEvenProduct = true; } } return isEvenProduct; } public static void main(String[] args) { CheckForEvenProduct check = new CheckForEvenProduct(); System.out.println("Does the array contains product of two distict elemets which is even? " + check.doesItContainsEvenProduct(arrayOfIntegers)); } } Output: case1: 32 54 3 8 787 45 1 4 9 7 Does the above array contains product of two distict elemets which is even? true case 2: 9 7 1 3
Does the above array contains product of two distict elemets which is even? false