hi this question is from http://www.anilbachi.8m.com . Please help me with solution. Q}State the output of the following code public class short{ public static void main(String args()){ int t=0; boolean t=true; boolean f=false,b; b=(t | | ((i++) ==0)); b=(f | | ((i+=2)>0)); System.out.println(i); }} a).0 b).1 c).2 d).3 I think the answer is 2. Am I right. Please help me.
Hi, First of all instead of int t = 0, it should be int i = 0. If it is so, you are right, what's the problem ??? in first statement: b=(t | | ((i++) ==0)), as t is true, i++ never get executed, so i remains 0. rest of it is simple.
Hi, I agree with Jonathan. Question is wrong as it has been used keyword ( short ). Output is nothing. Yes if you correct variable then you would get 2. - Golam Newaz
Madhu, The answere is 2. There should not be a space between short circuit operator. Please keep in mind while executing the code. public class short1{ public static void main(String args[]){ int i=0; boolean t=true; boolean f=false,b; b=(t | | ((i++) ==0)); System.out.println(b); b=(f | | ((i+=2)>0)); System.out.println(b); System.out.println(i); } }
[This message has been edited by venu gopal (edited February 06, 2001).]