- Enter 20 numbers from the keyboard, save them to the list and sort them into three other lists: the number is divided by 3 (
x % 3 == 0), divided by 2 (x % 2 == 0) and all others. Numbers that are divided into 3 and 2 at the same time, for example, 6, fall into both lists. - The
printListmethod should display all the elements of the list on a new line. - Using the
printListmethod,printListthese three lists. First, the one forx % 3, then the one forx % 2, then the last one.
I made 1 and 2 points. How to make 3 points?
public class Solution { public static void main(String[] args) throws Exception { BufferedReader rd = new BufferedReader(new InputStreamReader(System.in)); ArrayList<Integer> list3 = new ArrayList<Integer>(); ArrayList<Integer> list2 = new ArrayList<Integer>(); ArrayList<Integer> list32 = new ArrayList<Integer>();` while(true) { String s = rd.readLine(); if (s.isEmpty()) break; int x = Integer.parseInt(s); if (x % 3 == 0) { list3.add(x); printList(list3); } else if (x % 2 == 0) { list2.add(x); printList(list2); } else if ((x % 3 == 0) && (x % 2 == 0)) { list32.add(x); printList(list32); } } } public static void printList(List<Integer> list) { //напишите тут ваш код System.out.println(list); } }