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.

14th Jan 2017, 2:42 PM
Jon Shillings
4 Respostas
+ 2
You had to use == and not = in the ifs
14th Jan 2017, 2:54 PM
Golan
0
haha. whoops! thx sometimes it's the simplest things
14th Jan 2017, 2:55 PM
Jon Shillings
0
the goal was to only add multiples of 3 and 5 to a linkedlist. Thank you for the feedback
14th Jan 2017, 3:35 PM
Jon Shillings
- 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... :)
14th Jan 2017, 2:56 PM
ghostwalker13
ghostwalker13 - avatar