Page 1 of 1
enthuware.ocajp.i.v7.-2-.1065
Posted: Thu Mar 22, 2018 4:13 pm
by ashishrai.kv
Code: Select all
class LoopTest{
public static void main(String[] args) {
boolean flag = true;
if(flag == false){
System.out.println("1");
}else if(!flag&flag){//line 2
System.out.println("2");
}else if(!flag){
System.out.println("3");
}else System.out.println("4");}}
on above question when i change the elseif in //line2, i am getting output as 4.
can you give me a reference or examples of which operator &&,& ?,||,^. gives what output, in book its quite confusing?
Re: enthuware.ocajp.i.v7.2.1065
Posted: Thu Mar 22, 2018 8:51 pm
by admin
You are asking a very broad question that cannot be answered in a post. You may start with this:
https://stackoverflow.com/questions/719 ... nd-in-java
Re: enthuware.ocajp.i.v7.-2-.1065
Posted: Fri Mar 23, 2018 3:26 am
by ashishrai.kv
ok thanks for the link, will look into it
but can you help me with whats happening in //line2
Re: enthuware.ocajp.i.v7.-2-.1065
Posted: Fri Mar 23, 2018 4:26 am
by admin
Well, the value of flag is true, so !flag&flag will be !true & true => false & true => false
Re: enthuware.ocajp.i.v7.-2-.1065
Posted: Fri Mar 23, 2018 8:35 am
by ashishrai.kv
Thanks,