I am trying to determine if the numbers in an array list are divisiable by all of numbers in antoher arraylist. My code below outputs all of the numbers from the listdiv
list that are disible by any divisors in the listdivisor
. I would like to output the values that are divisible by all divisiors in the list not any of them. For example If I have listdiv = [1,2,3,,5,8] and listdivisor= [2,4]. the expected output should be 8 , but this code outputs 2 and 8 .
Thank you !your effort will be greatly appreciated!
for (int i = 0; i < listdiv.size(); i++) {
for (int c = 0; c < listdivisor.size(); c++) {
if (listdiv.get(i) % listdivisor.get(c) == 0) {
System.out.println("final results are : " + listdiv.get(i));
}
}
}