Menu
Topics Index
...
`

Print Bytes of a String


If you need explanation Read this topic

If you need Answer Take test on this topic

Print Bytes of a String
What will be the output of the following program?
public class ByteExample
{
    public static void main(String[] args)
    {
        String str = "Merit";
        System.out.println((int) 'X');
        byte[] bytes = str.getBytes();
        for (byte byt : bytes)
            System.out.print(byt + " ");
    }
}

A. 88
M e r i t
B. 88 
77 101 114 105 116
C. X
M e r i t
D.
77 101 114 105 116
E. Compilation Error or Runtime Error
Topic: Java Character Extraction - Java String getBytes() Method

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 it prints the Byte values of merit

Posted by Bharath Yelchuri    2014-09-02 12:45:07


Ans:B in firast sop statement asci no of  "X'  will be dispalyed 88. in for loop it displays asci no of each character of  "Merit" String

Posted by Indrasena Reddy    2014-09-02 12:45:10


ANs is B first print stmt prints X asci value and str Merit byte values stored in array and prints

Posted by Naga Sinst    2014-09-02 12:48:09


ans is B

Posted by Raju VarshnEy    2014-09-02 12:58:38


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-09-03 04:17:06


© meritcampus 2019

All Rights Reserved.

Open In App