Menu
Topics Index
...
`

If condition1979


If you need explanation Read this topic

If you need Answer Take test on this topic

If condition1979
What will be the output of the following program?
public class BigDelight {
    public static void main(String[] args) {
        for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) {
            if (b == 0x90)
                System.out.print("Printing");
            if (b == (byte) 0x90)
                System.out.print("Printing");
            if ((b & 0xff) == 0x90)
                System.out.print("Printing");
        }
    }
}

A. Printing
B. PrintingPrinting
C. PrintingPrintingPrinting
D. (EMPTY)
E. Some other output
F. Compilation Error or Runtime Error
Topic: Creating Objects for Primitive Data Types (Byte, Short)

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.

Answer : B
> The first if loop does  not execute as b holds a value of -127 and 0x90 will hold a value of 144
> The Second and third if loop return true as the typecast "  (byte)0x90 " returns  value that  is equal to b

Posted by Deepak Kumar Yadav    2014-05-16 12:55:03


Ans is B as b is compared with byte code and address of byte code and condition leads true it prints "printing" and in coondition two values matched so it prints 2 times

Posted by Bharath Yelchuri    2014-05-16 12:55:57


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

Posted by Merit Campus    2014-05-19 05:55:17


© meritcampus 2019

All Rights Reserved.

Open In App