Can someone explain why it wouldn't pass the 3rd, 4th and 5th requirements?
I got frustrated and copy pasted the solution, just to pass this task.
Scanner input = new Scanner(System.in);
ArrayList<Integer> numList = new ArrayList<Integer>();
for (int i = 0; i < 20; i++) {
String s = input.nextLine();
numList.add(Integer.parseInt(s));
}
ArrayList<Integer> divBy3 = new ArrayList<Integer>();
ArrayList<Integer> divBy2 = new ArrayList<Integer>();
ArrayList<Integer> divBy3And2 = new ArrayList<Integer>();
for (int i = 0; i < numList.size(); i++) {
int x = numList.get(i); // gets number index position through each loop
if(x % 3 == 0 && x % 3 != 1 && x % 2 == 0 && x % 2 != 1) {
divBy3And2.add(x);}
else if (x % 3 == 0) {
divBy3.add(x);
}else if (x % 2 == 0) {
divBy2.add(x);
}
}
System.out.print("Divisible by 3: ");
printList(divBy3);
System.out.print("\nDivisible by 2: ");
printList(divBy2);
System.out.print("\nDivisible by 2 and 3: ");
printList(divBy3And2);
}
public static void printList(List<Integer> list) {
for (Integer x : list) {
System.out.print(x + " ");
}
}
}