No one has said WHY it is so important to order the declarations just so. I don't see why it has anything to do with the outcome - does the memory assign memory locations in the order they come in? I tried a couple different orders of declarations and got the same result each time ( which is correct ), but I only verified when I put them in the order l, l3, l2, l1. And the error message was 'Make sure the numbers divisible by 3 & 2 are on both lists.' It works correctly no matter what order the lists are declared. I have traced thru the answer by hand 4 times and it comes out correctly! Here is my code for the 'sorting'.
for (int i = 0; i < 20; i++) {
if ((l.get(i) % 3 == 0) || (l.get(i) % 2 == 0)) {
if (l.get(i) % 3 == 0) l3.add(l.get(i));
if (l.get(i) % 2 == 0) l2.add(l.get(i));
}else{
l1.add(l.get(i));
}
}
Please let me know what I'm missing. Thanks
Order of Declarations?
Under discussion
Comments (3)
- Popular
- New
- Old
You must be signed in to leave a comment
MIHAI
17 November 2020, 21:40
try it like this for (int i = 0; i < l.size(); i++)
0
Misiu
10 August 2020, 10:10
I think this task requires: do exactly what is given in conditions. And conditions say: order must be - 3, 2, others.
Why such conditions? But why not? I think it's just an idea of verification makers.
0
Gil Allen
10 August 2020, 20:30
Doesn't sound very important to me@#$%^&*( I still don't believe the conditions made it clear that that was the order. The requirements said the other three will be supplemental. oh well - i feel like a puppet on a string. or maybe a puppet on an int. Ha
Thanks for responding!
0