Menu
Topics Index
...
`

Order Lines


If you need explanation Read this topic

If you need Answer Take test on this topic

Order Lines
In which order should the lines A, B, C, D be arranged such that it gets the required output?
/* Required output
a = 4 b = 8 c = -5
*/

class OrderLines
{
    public static void main(String[] args)
    {
        int a = 27 / 4 + 9;
        int b = 52 / 6 - 3;
        int c = 3;
        c = a++ - b; // LINE A
        a = a * b; // LINE B
        b = b + a; // LINE C
        a = (a < c) ? a % c : c % a; // LINE D
        System.out.println("a = " + a + " b = " + b + " c = " + c);
    }
}

A. A, B, C, D
B. B, D, C, A
C. B, A, D, C
D. A, B, D, C
Topic: Ternary Operator 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 B.
at initialization a = 15,b=5,c=3.
At line B => a = 15*3 = 45
At line D => a = 45<3 is false,so c%a=3%45=3 ===> a=3
At line C => b = 5+3 = 8
At line A => c = a++ - b = 3 - 8 = -5... after this line a is incremented.
finally a = 4 b = 8 c = -5

Posted by Gopinath Manchikanti    2014-08-14 08:36:45


b...initial value of are a=15 b=5 c=3
frstly line b is exectd so
a=45
then d is executd
so aftr trnary oprtr a bcms 3...
den line c
b = 8
and finaly line a exectd
wich chngs valu of c n
n c=-5
n finaly values r
a=4 b=8 C=-5

Posted by Asma Mujtaba Khan    2014-08-14 09:36:26


b

Posted by Deepika Deepu    2014-08-14 13:45:45


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

Posted by Merit Campus    2014-08-15 06:05:42


© meritcampus 2019

All Rights Reserved.

Open In App