all the lists are printed from printmethod on a new line.
Seems like I did it correctly but I must be missing something in the code?
Thanks for looking!
package com.codegym.task.task07.task0713;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
/*
Playing Javarella
*/
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
ArrayList<Integer> mainList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);
for (int i = 0; i < 20; i++) {
int num = scanner.nextInt();
mainList.add(num);
}
printList(mainList);
}
public static void printList(List<Integer> list) {
//write your code here
ArrayList<Integer> divisibleByThree = new ArrayList<>();
ArrayList<Integer> divisibleByTwo = new ArrayList<>();
ArrayList<Integer> remainingList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
if (list.get(i) % 3 == 0) {
divisibleByThree.add(list.get(i));
}
if (list.get(i) % 2 == 0) {
divisibleByTwo.add(list.get(i));
}
if ((list.get(i) % 3 != 0) && (list.get(i) % 2 != 0)) {
remainingList.add(list.get(i));
}
}
for (int var : divisibleByThree){
System.out.println(var);
}
for (int var : divisibleByTwo){
System.out.println(var);
}
for (int var : remainingList){
System.out.println(var);
}
}
}