Created
April 14, 2020 04:52
-
-
Save thmain/b5bf7395f0f1e1b1278330650dac2f51 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.Arrays; | |
| public class CountPairsWithOddSum { | |
| public static void countPairs(int [] input){ | |
| System.out.println("Given Input: " + Arrays.toString(input)); | |
| int evenCount=0; | |
| int oddCount=0; | |
| for (int i = 0; i <input.length ; i++) { | |
| if(input[i]%2==0) | |
| evenCount++; | |
| else | |
| oddCount++; | |
| } | |
| int evenPairs = evenCount*oddCount; | |
| System.out.println("Number of odd pairs: " + evenPairs); | |
| } | |
| public static void main(String[] args) { | |
| int [] input = {6, 7, 1, 3, 2, 5, 4}; | |
| countPairs(input); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment