Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class OddsAndEvens
- {
- private static int countEm(int[] array, boolean odd)
- {
- int oddCount = 0;
- for(int i = 0; i < array.length; i++)
- {
- if(array[1] % 2 == 0)
- {
- oddCount += 1;
- }
- }
- if (odd)
- {
- return oddCount;
- }
- return array.length - oddCount;
- }
- public static int[] getAllEvens(int[] array)
- {
- int[] newArray = new int[countEm(array, false)];
- int arrayCount = 0;
- for(int i = 0; i < array.length; i++)
- {
- if(array[i] % 2 == 0)
- {
- newArray[arrayCount] = array[i];
- arrayCount++;
- }
- }
- return newArray;
- }
- public static int[] getAllOdds(int[] array)
- {
- int[] newArray = new int[countEm(array, true)];
- int arrayCount = 0;
- for(int i = 0; i < array.length; i++)
- {
- newArray[arrayCount] = array[i];
- arrayCount++;
- }
- return newArray;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement