/** * COMP 1711 (Fall 2005) * * Solution to Challenge Problem #1 (The Odd/Even Couple) * * @author Based on a solution by Emily Orr * @version Dec-08-2003 */ public class Problem01 { public static void oddEven(int[] arr) { int evenIndex = 0; int oddIndex = 0; int [] even = new int[arr.length]; int [] odd = new int[arr.length]; for (int i = 0; i < arr.length; i++){ if(arr[i]%2 == 0){ even[evenIndex] = arr[i]; evenIndex++; } // end if else if(arr[i]%2 == 1){ odd[oddIndex] = arr[i]; oddIndex++; } // end else } // end for int arrIndex = 0; for (int i = 0; i < oddIndex; i++){ arr[arrIndex] = odd[i]; arrIndex++; } // end for for (int i = 0; i < evenIndex; i++){ arr[arrIndex] = even[i]; arrIndex++; } // end for // Print out the modified array to test it for (int i = 0; i < arr.length; i++){ System.out.println(arr[i]); } // end for } // end oddEven(int[]) } // end class Problem01