Thanks for your replies!
package com.codegym.task.task07.task0713;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Playing Javarella
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
// Declare and initialize main list.
ArrayList <Integer> list = new ArrayList<>();
// Read 20 numbers from the keyboard and add them to the main list.
for (int j = 0; j < 20; j++) {
String s = reader.readLine();
int x = Integer.parseInt(s);
list.add(x);
}
// call printList method
printList(list);
}
public static void printList(List<Integer> list) {
// Declare and initialize 3 supplementary lists.
ArrayList <Integer> listDiv_3 = new ArrayList<>();
ArrayList <Integer> listDiv_2 = new ArrayList<>();
ArrayList <Integer> listOthers = new ArrayList<>();
// Add numbers to the supplementary lists
for (int i = 0; i < 20; i++) {
if (list.get(i)%3 == 0 && list.get(i)%2 == 0) {
listDiv_3.add(list.get(i));
listDiv_2.add(list.get(i));
} else if (list.get(i)%3 == 0) {
listDiv_3.add(list.get(i));
} else if (list.get(i)%2 == 0) {
listDiv_2.add(list.get(i));
} else {
listOthers.add(list.get(i));
}
}
// print each list element of the supplementary lists on a new line
for (int i = 0; i < listDiv_3.size(); i ++) {
System.out.println(listDiv_3.get(i));
}
for (int j = 0; j < listDiv_2.size(); j++ ) {
System.out.println(listDiv_2.get(j));
}
for (int k = 0; k < listOthers.size(); k++) {
System.out.println(listOthers.get(k));
}
}
}