Car repairs An owner of an auto repair shop wishes to organise his team of mechanics at the beginning of the day. To make the distribution of work equal, he organises 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
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int[] arr = new int[9];
int[] rez = new int[9];
for (int i = 0; i < arr.length; i++) {
System.out.print("Car " + (i + 1) + ": ");
arr[i] = in.nextInt();
}
int x = 0;
for (int i : arr) {
if(i%2 == 0){
rez[x] = i;
x++;
}
}
for (int i : arr) {
if(i%2 != 0){
rez[x] = i;
x++;
}
}
for (int i : rez) {
System.out.print(i + " ");
}
}
}
Comments
Leave a comment