Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

What will be the output of the following program?
public class Blue {
    public static void main(String s[]) {
        int x = 20;
        int y = 25;
        if (++x < (y = y -= 4) || (x = x += 4) > y) {
            System.out.println(x + " " + y);

A. 25 20
C. Some other output
D. Compilation Error or Runtime Error
Topic: if Condition In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is Ans is C.x wil 25 and y is 21

Posted by Uday Kumar    2014-07-25 13:15:59

ans. is c. because
++x increment x first time and x+=4 makes it 25.
y will decrease to 21 by 1st condition and thereafter both conditions will becomes true and ans. will display.....

Posted by Shubham Bansal    2014-07-25 14:00:50


Posted by Samyuktha Reddy    2014-07-25 14:03:56

i forgot what that property is called.. but it says at the end of every logical sentence( marked by closing bracket of any condition or ';'  )  all the side effects (variable change) are guaranteed
so at the end of line number 5 before the program moves on no matter what all the changes are guaranteed by the java compiler
output will be 25 21

Posted by Tushar Ghude    2014-07-25 14:38:22

C output will be 25 21

Posted by Ria Gupta    2014-07-25 14:42:17


Posted by Ananth Sathvick    2014-07-25 14:47:18


Posted by Neelima Nadikuda    2014-07-25 20:58:55


Posted by Ayesha Zafar    2014-07-26 11:21:18

when will be the result declared???

Posted by Shubham Bansal    2014-07-27 17:02:48

For the Friday daily doses, the results will be published only on Monday. For other days it will be next day. So kindly be patient. :-)

Posted by Merit Campus    2014-07-28 06:34:34

Congratulations Uday Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-28 06:51:31

why uday kumar??
he doesn't explain it!!!

Posted by Shubham Bansal    2014-07-28 06:53:50

Shubham Bansal. It is our mistake. Thanks for highlighting. We are sending a recharge link to you as well. Our apologies.

Posted by Merit Campus    2014-07-28 11:39:03


Posted by Shubham Bansal    2014-07-28 12:57:24

© meritcampus 2019

All Rights Reserved.

Open In App