0
How the following code results in false output?
public class Program { public static void main(String[] args) { boolean v = (true||!(!false ))?false:true ; if(false){ v=true; } else { v=v==true; } System.out.print(v); } } //What is v=v==true?
4 Respuestas
+ 8
Line 1:- boolean v = (1) ? (2) : (3)
means if 1 is true, then assign v =2, else v=3.
For your line , 1 is true, hence 2 is assigned, 2 is false.
Hence v is false
if(false) is never gonna run,
else will run
v=v==true;
this is same as
v = (v == true);
that is, if v==true , then assign v as true, else assign it false.(== returns either true or false)
since v is false and false == true is false , v==true is false .hEnce v is assigned false.
+ 7
at boolean v. v is false
if and else. execute else v = (false==true) now v = false
System.out.print(v) Search value v and v is false print false
+ 3
Anytime @Prathamesh
0
Thanks Singh... That helped