0
What do the two equal signs mean? E.g. x==10 . Somebody help me!
Java
6 Réponses
+ 1
if (a == 5) means, variable a equals to 5? (condition checking)
While, a = 5, variable x taking a value as 5 (assigning value)
+ 1
== is an logic operator and it is requesting a boolean it should not be confused with = which is used to for example set a value to a variable. You can use == to set a condition like already described from the other comments. So it is used for testing if to values are equal(works for each datatype).
0
When we wish to make a comparison, such as in an if statement, we use the double equals sign (==). A simple example would be the following
if ( a == b ) then System.out.println ("Match found!");
Now consider what would have happened if we used an assignment operator instead. A would be assigned the value of B - destroying the current contents of A and giving us an incorrect comparison. Finding this type of error can be difficult, because the two operators look so similar. So why does Java use such confusing operators? Java draws its roots from C, which shares the same problem. Unfortunately, its something that all Java programmers must learn to live with.
0
Another example "2" == 2 // true
"2" === 2 // false
0
This two equal signs, as you call them, compare what is on the left side to what is on the right side of them. If variable x "remembers" value 10, then the left side is equal to the right side and the expression (equation) is true. If variable x "remembers" something other than value 10, then expression is false. You can use it in "if" statement: if (x == 10) // do something
0
we always use '==' sign like x==5 to show that x is equal to 5 , we can't use 1 '=' sign for this because 1 '=' sign is used to assign a value to a variable.