public class Solution {
public static void printList(ArrayList<Integer> list) {
for (int x: list) {
System.out.println(x);
}
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> mainLisst = new ArrayList<Integer>();
for (int i = 0; i < 20; i++) {
mainLisst.add(Integer.parseInt(reader.readLine()));
}
ArrayList<Integer> splitedOfTwo = new ArrayList<>();
ArrayList<Integer> splitedOfThree = new ArrayList<>();
ArrayList<Integer> other = new ArrayList<>();
for(int x :mainLisst){
if(x%2==0) {
splitedOfTwo.add(x);
}
else if (x % 2== 0 && x% 3==0){
splitedOfTwo.add(x);
splitedOfThree.add(x);
}
else if (x%3==0){
splitedOfThree.add(x);
}
else {
other.add(x);
}
}
printList(splitedOfTwo);
printList(splitedOfThree);
printList(other);
}
}
Evhen Ivchenko
8 уровень
Задача уже была решена , но повторно прохожу курс , посмотрите кто то грамотно ли написан код , в IDEA все работает
Решен
Комментарии (1)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
Стас Пасинков Software Developer в Zipy Master
22 июня 2022, 17:40решение
ні.
у вас числа, які діляться на 2 і на 3 потраплятимуть тільки у ліст тих, шо діляться на 2
+3