+ 1
Can some one explain this code
public class Program { public static void main(String[] args) { boolean b=false; if(b=false) System.out.println("1"); else if(b) System.out.println("2"); else if(!b) System.out.println("3"); else System.out.println("4"); } }
6 Answers
0
if the 1st if statement was
if(b==false)
then that has been executed
and the ans has been 1 (e)
cause b==false
== means checking if the value is same or not
= means assigning a value
+ 4
are you sure you copied it as it is?
b=false check this
+ 1
thanks nw I understand
0
yes it's a objective question here are the options
a) fail to compile
b)2
c)no output
d)4
e)1
f)3
g)runtime error
0
ans is 3
i mean f
0
b=false
means b is false now..
so if(b)--> if(false)
no execution
else if(b)--> else if(false)
no execution
else if(!b)--> else if(not b)--> else if (not false)--> else if(true)
executes
else part dont execute..
if(True)//if(not False)//if(8)//if(7==7)
this things always ececutes