public class Solution {
public static void main(String[] args) throws Exception {
ArrayList<Integer> list = new ArrayList<Integer>();
ArrayList<Integer> list_3 = new ArrayList<Integer>();
ArrayList<Integer> list_2 = new ArrayList<Integer>();
ArrayList<Integer> list_other = new ArrayList<Integer>();
BufferedReader dr = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 20; i++) {
String s = dr.readLine();
Integer b = Integer.parseInt(s);
list.add(i, b);
}
for(int i = 0; i < 20; i++) {
Integer x = list.get(i);
if (x % 3 == 0) {
list_3.add(x);}
else if(x % 2 == 0) {
list_2.add(x);}
else if(x % 2 == 0 && x % 3 == 0){
list_3.add(x);
list_2.add(x);}
else {
list_other.add(x);}
}
printList(list_3);
printList(list_2);
printList(list_other);
}
public static void printList(List<Integer> list) {
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
}
}
Миша
15 уровень
что не так?
Архивный
Комментарии (2)
- популярные
- новые
- старые
Для того, чтобы оставить комментарий Вы должны авторизоваться
--------Master
11 августа 2018, 10:44решение
Подумай логически, это условие else хоть когда-нибудь может выполниться (учитывая, что else означает иначе, т.е. невыполнение условий выше)?
+2
Миша
11 августа 2018, 10:54
Спасибо)
+1