Proper output still!
package com.codegym.task.task07.task0713;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Playing Javarella
1. Enter 20 numbers from the keyboard, save them in a list,
-and then sort them to three other lists:
Numbers divisible by 3 (x%3==0), numbers
-divisible by 2 (x%2==0), and all other numbers.
Numbers simultaneously divisible by 3 and 2 (for example 6) go into both lists.
The order in which the lists are declared is very important.
2. The printList method should display each list item on a new line.
3. Using the printList method, display these three lists.
-First, the list for x%3, then the list for x%2, and then the last list.
*/
public class Solution {
public static ArrayList<Integer> num_al = new ArrayList<Integer>();
public static ArrayList<Integer> div3_al = new ArrayList<Integer>();
public static ArrayList<Integer> div2_al = new ArrayList<Integer>();
public static ArrayList<Integer> divother_al = new ArrayList<Integer>();
public static void main(String[] args) throws Exception {
//write your code here
int cnum = 0;
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 20; i++) {
cnum = Integer.parseInt(reader.readLine());
num_al.add(cnum);
}
for(int num : num_al) {
if(num % 2 == 0 && num % 3 == 0) {
div2_al.add(num);
div3_al.add(num);
}
else if(num % 2 == 0)
div2_al.add(num);
else if(num % 3 == 0)
div3_al.add(num);
else
divother_al.add(num);
}
printList(num_al);
//printList(divother_al);
//printList(div3_al);
}
public static void printList(List<Integer> list) {
//write your code here
for(int x3 : div3_al)
System.out.println(x3);
for(int x2 : div2_al)
System.out.println(x2);
for(int xother : divother_al)
System.out.println(xother);
}
}