+ 1

Whats the difference between = and ==

I just did a coding lesson on scanner booleans where if statements were used to see if a situation was either false or true with a boolean input, but whenever I called upon the code holding the input and used = to see if it was literally true or false, it always defaulted to true, whereas == called upon the actual input. I have no idea why this is and it flusters me. I get == is for literals, but what is the purpose for = then? It usually works just fine with numbers and strings

6th Jan 2021, 1:40 AM
Serana Zentha
Serana Zentha - avatar
2 Answers
+ 3
In most programming languages(including Java), = represents the assignment operator(it assigns a value to a variable) and == represents a comparison operator(it checks whether or not two values are them same).
6th Jan 2021, 2:10 AM
Jianmin Chen
Jianmin Chen - avatar