0

What do the two equal signs mean? E.g. x==10 . Somebody help me!

Java

4th Nov 2016, 8:13 PM
Ariel Boutcher
Ariel Boutcher - avatar
6 Antworten
+ 1
if (a == 5) means, variable a equals to 5? (condition checking) While, a = 5, variable x taking a value as 5 (assigning value)
4th Nov 2016, 8:48 PM
Bekzod
Bekzod - avatar
+ 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).
6th Nov 2016, 10:53 AM
Maxim J
Maxim J - avatar
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.
4th Nov 2016, 8:29 PM
Familiar Mink
Familiar Mink - avatar
0
Another example "2" == 2 // true "2" === 2 // false
4th Nov 2016, 8:30 PM
Familiar Mink
Familiar Mink - avatar
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
4th Nov 2016, 8:31 PM
Mike Levis
Mike Levis - avatar
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.
6th Nov 2016, 4:52 AM
Bhargav Kaushik
Bhargav Kaushik - avatar