You are getting 0 as the output because the condition sum>20 is false & the program jumps out of the for loop printing sum as 0.
Change the condition to sum<=20.<br />
Originally posted by lakshmi panda:<br /> i came across this question in JQ++. it is as follows:<br /> public class Test <br /> {<br /> public static void main(String[] args)<br /> {<br /> int sum=0;<br /> for(int i=0,j=10;sum>20;++i,--j)
{
sum +=i+j;
}
System.out.println(sum);
}
}
i thought the answer would be 20 but instead when i saw the answer it was 0.could anyone please explain this .
Thanks
Lakshmi