My code seems correct but it does not work
package com.codegym.task.task07.task0713;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.*;
/*
Playing Javarella
1. Enter 20 numbers from the keyboard, save them in a list, and then sort them to three other lists:
Numbers divisible by 3 (x%3==0), numbers divisible by 2 (x%2==0), and all other numbers.
Numbers simultaneously divisible by 3 and 2 (for example 6) go into both lists.
The order in which the lists are declared is very important.
2. The printList method should display each list item on a new line.
3. Using the printList method, display these three lists.
First, the list for x%3, then the list for x%2, and then the last list.
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
ArrayList<Integer> list1 = new ArrayList<Integer>();
ArrayList<Integer> list2 = new ArrayList<Integer>();
ArrayList<Integer> list3 = new ArrayList<Integer>();
ArrayList<Integer> list4 = new ArrayList<Integer>();
Scanner sc = new Scanner(System.in);
for (int i=0; i<20; i++) {
int readInt = sc.nextInt();
list1.add(readInt);
if ((list1.get(i) % 3 == 0) && (list2.get(i) % 2 != 0)) {
list2.add(list1.get(i));
}
else if ((list1.get(i) % 2 == 0) && (list2.get(i) % 3 != 0)) {
list3.add(list1.get(i));
}
else if ((list1.get(i) % 3 == 0) && (list1.get(i) % 2 == 0)) {
list2.add(list1.get(i));
list3.add(list1.get(i));
}
else if ((list1.get(i) % 3 != 0) && (list1.get(i) % 2 != 0)) {
list4.add(list1.get(i));
}
}
printList(list2);
printList(list3);
printList(list4);
}
public static void printList(List<Integer> list) {
//write your code here
/*
for (int i=0; i< list.size(); i++) {
System.out.println(list.get(i));
}
*/
for (Integer i : list) {
System.out.println(i);
}
}
}