| Author |
Doubt on operators
|
Venkat KG
Greenhorn
Joined: Nov 13, 2005
Posts: 10
|
|
Hi, Can any one help out in this prog.I really cud not undersatnd what is happening in Line 1 and Line 2 .Why the o/p is printing as 122. public static void main(String argv[]){ Test1 td = new Test1(); td.samcov(); } public void samcov(){ int i=1; int j=2; if((i==20) && (j==(i=i*2))){ //Line1 } System.out.print(i); if((i==20) & (j==(i=i*2))){} // Line 2 System.out.print(i); int x = i & 2; System.out.print(x); } }
|
 |
shaikkhadar basha
Greenhorn
Joined: Nov 22, 2005
Posts: 2
|
|
In Line1 && operator is used. In this case since LHS expression evaluates to false, RHS expression doesn't evaluate. In Line2 & operator is used. In this case both LHS,RHS expression gets evaluated always. So RHS j==(i=i*2)) assigns 2(i=i*2) to i and j.
|
 |
 |
|
|
subject: Doubt on operators
|
|
|