Answer to Question #319832 in Java | JSP | JSF for hussain

Question #319832

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


1
Expert's answer
2022-03-28T14:28:49-0400
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 + " ");
        }
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS