0
Required Variable, Found Value
Why would I be getting an unexpected type error in this piece of code? for(int a = 1; a <= 10; a++){ if( a % 3 = 0 ){ example.add(a); } else if ( a % 5 = 0 ){ example.add(a); } } The errors are found in the if statements, both of them.
4 Answers
+ 2
You had to use == and not = in the ifs
0
haha. whoops! thx
sometimes it's the simplest things
0
the goal was to only add multiples of 3 and 5 to a linkedlist. Thank you for the feedback
- 1
You might need a 'else'-statement to handle "if anything else".
(But I think you didn't include it so it would run either way, I'm not quite sure.)
Also, the Top-most 'if'-statement needs a 'else'-statement to close off any errors (as said above).
I'm not sure on the topic myself, but I know that many languages share some of the concepts with Java - meaning syntax will most likely remain unchanged.
Example: JavaScript, etc.
I hope this helps... :)