The program fails at this condition: The program should display the divBy3, divBy2, and others lists using the printList() method.
While clearly it is printing them...
package en.codegym.task.jdk13.task07.task0713;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
/*
Three arrays
*/
public class Solution {
public static ArrayList<Integer> numbers = new ArrayList<>();
public static ArrayList<Integer> divBy3 = new ArrayList<>();
public static ArrayList<Integer> divBy2 = new ArrayList<>();
public static ArrayList<Integer> others = new ArrayList<>();
public static void main(String[] args) throws Exception {
//write your code here
//write your code here
Scanner sc = new Scanner(System.in);
numbers = new ArrayList<Integer>();
divBy3 = new ArrayList<Integer>();
divBy2 = new ArrayList<Integer>();
others = new ArrayList<Integer>();
for (int i = 0; i < 20; i++) {
numbers.add(sc.nextInt());
if (numbers.get(i) % 3 == 0) divBy3.add(numbers.get(i));
if (numbers.get(i) % 2 == 0) divBy2.add(numbers.get(i));
if (((numbers.get(i) % 3) != 0) & ((numbers.get(i) % 2) != 0)) others.add(numbers.get(i));
}
printList(divBy3);
printList(divBy2);
printList(others);
}
public static void printList(ArrayList<Integer> list) {
//write your code here
for (Integer n : list) {
System.out.println(n);
}
}
}