Menu
Question Index
...

What will be the output of the following program?

public class ByteExample1
{
    public static void main(String[] args)
    {
        String str = "Merit_";
        byte[] bytes = str.getBytes();
        for (byte byt : bytes)
        {
            byte b5 = (byt > 65 && byt < 90) ? byt : (byt > 97 && byt < 122) ? byt : (int) 'X';
            System.out.print(b5 + " ");
        }
    }
}


77 101 114 105 116 X
M e r i t 88
77 101 114 105 116 88
Compilation Error because int can not be assigned to byte
Compilation Error or Runtime Error for some other reason

Doubts

Problems

Topic: Java Character Extraction - Java String getBytes() Method

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App