Example.java
number == 0
Suppose you have code like the one above. The meaning is that 0 is assigned to the variable number, which is equal to 0 on the right.
Then, in the case of letters ...? : thinking:
Example.java
fruit == "Apple"
Isn't it? ?? : thinking: I think. In fact, it's a mistake. In Java, strings are supposed to be incomparable with ==. So what to do ...
String comparison.
String type variable.equals(String of comparison partner)
Will be: smile: So the previous code is
Example.java
fruit.equals("Apple")
Will be: smile:
As an aside, using == in a string doesn't cause a compile error: sweat_smile: There is a bad problem that it can be executed but the movement is strange: sweat_smile: It's awkward to find an error just because it doesn't cause a compile error: sweat_smile:
: sunny: && is used when you want to match all two or more conditions such as "female and born in Tokyo". :sunny: ||Is used when you want to match something that meets any of the conditions, such as "female or born in Tokyo".
(Example) Over 20 years old and born in May
Example.java
age >= 20 && month == 5
True if you are over 20 years old and born in May and all the conditions are met, otherwise false.
(Example) Over 20 years old or born in May
Example.java
age >= 20 || month == 5
False if you are 20 years old or older or born in May and none of the above apply, otherwise true.
Recommended Posts