I'm getting correct output but 1st and last 2 conditions are not satisfying.
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 {
private static ArrayList<Integer> list1 = new ArrayList<Integer>();
private static ArrayList<Integer> list2 = new ArrayList<Integer>();
private static ArrayList<Integer> list3 = new ArrayList<Integer>();
private static ArrayList<Integer> list4 = new ArrayList<Integer>();
public static void main(String[] args) throws Exception {
//write your code here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i=0; i<20; i++){
list1.add(i, Integer.parseInt(reader.readLine()));
}
printList(list1);
}
public static void printList(List<Integer> list) {
//write your code here
for(int j=0; j<20; j++){
int num = list1.get(j);
if(num%2 == 0 && num%3 == 0){
list2.add(num);
list3.add(num);
}
else if(num%3 == 0)
list2.add(num);
else if(num%2 == 0)
list3.add(num);
else
list4.add(num);
}
for(int k=0; k<list2.size(); k++){
System.out.println(list2.get(k));
}
for(int l=0; l<list3.size(); l++){
System.out.println(list3.get(l));
}
for(int m=0; m<list4.size(); m++){
System.out.println(list4.get(m));
}
}
}