Menu
Topics Index
...
`

Convert and print bytes


If you need explanation Read this topic

If you need Answer Take test on this topic

Convert and print bytes
What will be the output of the following program?
public class Quiz
{
    public static void main(String[] args)
    {
        String str = "Dpnqvufs-";
        byte[] bytes = str.getBytes();
        for (byte byt : bytes)
        {
            System.out.print(((char)(int)(char)(char)(int)(int)(char)(int)(int)((char)byt - 1)) + " ");
        }
    }
}

A. D p n q r u f s -
B. 67 111 109 112 113 116 101 114 44
C. B n l o t s d q +
D. C o m p u t e r ,
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 D.evry tim we are accessing its previous char n printing

Posted by Uday Kumar    2014-06-17 03:36:07


answer is E because char prints error

Posted by Vijaya Vijaya    2014-06-17 05:24:27


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-06-18 04:05:12


© meritcampus 2019

All Rights Reserved.

Open In App