+ 1
Why if condition not executes if we only put an integer inside condition in Java.
int x=1; if (x){ Sop("true"); else Sop("false"); Whats wrong here?
9 Respuestas
+ 3
Devendra Yadav cause x is integer. You should make it boolean.
+ 2
Charitra Agarwal you are wrong
+ 1
This is because, anything which is not null, will give true..
X is 1.. so its true... it will give false only if x is 0... and true in all cases
+ 1
conditions in java have to be boolean type, not int
it is simpler, better readable, unambiguousand and less confusing
+
there is unclosed bracket {
Sop() is not defined here
int x=1;
if (x==1)
System.out.println("true");
else
System.out.println("false");
+ 1
Maria Vasilyova got it thanks
+ 1
zemiak thanks for answering.
+ 1
Maria Vasilyova
He took data type as int...
I gave answer keeping int in mind...
You can experiment it with your compiler once..🤗
+ 1
Charitra Agarwal
https://code.sololearn.com/cFQ3it1sSQQk/?ref=app
Good luck
You won't run this code on any jvm
0
Maria Vasilyova
Oh.. I see...
Java has a different structure..
This works in c++ and python.