Menu
Topics Index
...
`

Strings replacement


If you need explanation Read this topic

If you need Answer Take test on this topic

Strings replacement
What will be the output of the following program?
class StringBufferTest
{
    public static void main(String[] args)
    {
        String s = "Infinity2K13";
        StringBuffer sb = new StringBuffer(s);
        for (int i = 0; i < s.length(); i++)
        {
            char current = s.charAt(i);
            s.replace(current, Character.toUpperCase(current));
        }
        sb.replace(9, 10, " 20");
        System.out.println(s.split('2')[0] + sb.substring(9));
    }
}

A. Infinity 2013
B. INFINITY 2013
C. INFINITYK13
D. Infinity2K13
E. Compilation Error
Topic: Java Character Class

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 E beacase it requires one public class in main file

Posted by Manasa Jyothi Sree    2014-03-21 14:59:38


Ans is E because split method take string delimiter as its argument

Posted by Naga Sinst    2014-03-21 15:04:56


E. Compilation error occurs. The split method is supplied with an argument of  char type for which the method is not defined. The defined split() method expects a string variable as parameter.

Posted by Nikhil Sulibhavi    2014-03-21 15:11:37


E. in s.replace all the character in are replaced to uppercase and sb replaces 9 char to 20 and  split function must have string parameter but given as char it cannot match predefined function it gives compilation error

Posted by Navya Golla    2014-03-21 15:23:35


ans is E because there is no suitable method for split(char)  and the length actual and formal argument lists are various lengths

Posted by Adithya Aleti    2014-03-21 15:42:12


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

Posted by Merit Campus    2014-03-24 04:57:30


© meritcampus 2019

All Rights Reserved.

Open In App