That's right? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
24th Mar 2021, 7:19 AM
Alesh Boldrew
Alesh Boldrew - avatar
4 Answers
+ 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
24th Mar 2021, 7:43 AM
XXX
XXX - avatar
24th Mar 2021, 8:43 AM
Alesh Boldrew
Alesh Boldrew - avatar
0
Thanks!
24th Mar 2021, 7:57 AM
Alesh Boldrew
Alesh Boldrew - avatar
0
1. add and not get😁
24th Mar 2021, 8:03 AM
Alesh Boldrew
Alesh Boldrew - avatar