As we already know, it is possible that this code be evaluated as true thanks to the great answers of Erwin Bolwidt and phflack , I wanted to show that you need to pay special attention when working with a condition that looks like it is presented in the question, because sometimes, what you see may not be what you think.
This is my attempt to show that this code prints Success! on the console. I know I cheated a little , but I still think this is a good place to introduce it here.
Regardless of what the purpose of writing such code is, it is better to know how to cope with the following situation and how to check whether you are mistaken with what you think you see.
I used the Cyrillic alphabet 'a', which is a great Latin character 'a'. You can check the characters used in the if statement here .
This works because variable names come from different alphabets. They are different identifiers, creating two different variables with different values in each.
Please note that if you want this code to work correctly, the character encoding should be replaced by one that supports both characters, for example. all Unicode encodings (UTF-8, UTF-16 (in BE or LE), UTF-32, even UTF-7) or Windows-1251, ISO 8859-5, KOI8-R (thanks - Thomas Weller and Paŭlo Ebermann - for instructions of it):
public class A { public static void main(String[] args) { int = 0; int a = 1; if( == 0 && a == 1) { System.out.println("Success!"); } } }
(I hope you never have to deal with such problems in the future).
source share