- 1
That's right?
4 odpowiedzi
+ 3
When the for-loop in the main() function starts, all the ArrayLists are empty. But inside the for-loop, on line 13, 14, 15 and 16, you are accessing the 'i'th index of the ArrayLists using the .get() method. Did you meant to *add* elements to the ArrayLists using the .add() method?
This will fix the problem. But on line 13, 14 and 15, the conditions are a bit ill-formed. Let's take the example of the condition on line 13 for now. The condition is
num % 2 == 0 || (num % 2 == 0 && ......)
Here if 'num % 2' is 0, the condition will be true and the statement inside the if-block will be executed. But when 'num % 2' is not 0, then
(num % 2 == 0 && num % 3 == 0 && num % 5 == 0)
will also be false. Hence the right-hand-side of the OR operator has no significance. If the only significance of this if-condition is to add numbers divisble by 2 to listDivTwo, then the RHS of the OR operator can be removed. If not then please specify what you are trying to do.
Same thing with the conditions on line 14 and 15
0
Thanks!
0
1. add and not get😁