An owner of an auto repair shop wishes to organize his team of mechanics at the beginning of the day. To make the distribution of work equal, he organizes cars with an even amount of faults into bay 1 and cars with an odd amount of faults into bay 2. There are nine cars in total Write the pseudocode for the problem, then write a Java program to separate the even and odd number of car faults. Have all even numbers displayed first, then odd numbers at the end. The repairs required for each car are as follows. 18, 14, 12, 6, 4, 21, 19, 9, 3 Hint: WHILE LOOPS and IF.
public static void main(String[] args){
int[] inArray = {18, 14, 12, 6, 4, 21, 19, 9, 3};
int[] evenArray = Arrays.stream(inArray).filter(s -> s % 2 == 0).toArray();
int[] oddArray = Arrays.stream(inArray).filter(s -> s % 2 == 1).toArray();
System.out.println(Arrays.toString(evenArray));
System.out.println(Arrays.toString(oddArray));
}
Comments
Leave a comment