Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

What will be the output of the following program?
public class Names {
    public static void main(String[] args) {
        String Str = new String("Welcome to");
        Str += " give the correct option to win the dose";
        System.out.println(Str.replaceAll("(\\w)(\\s+)([\\.,])", ""));
        Str += "Hai Hello";
        System.out.println(Str.replace("[a-zA-Z]", ""));

A. Welcome to give the correct option to win the dose
Hai Hello
B. Welcometomeritcampuscomgivethecorrectoptiontowinthedose
C. Welcome to give the correct option to win the dose
Welcome to give the correct option to win the doseHai Hello
D. Welcometomeritcampuscomgivethecorrectoptiontowinthedose
WelcometomeritcampuscomgivethecorrectoptiontowinthedoseHai Hello
E. Some other output
F. Compilation Error or Runtime Error
Topic: Additional String Methods in Java

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.

c is the ans we append the string and print it the replaceAll doesn't work as it has syntactic error similarly we append another string and print it as we are failing with immutable feature of String objects. so we have to store the replace and then print t

Posted by Karteek Paruchuri    2013-11-20 08:55:25

answer is E as for the first time we print the complete string and for the second time we print only characters which are not alphabets

Posted by Mahesh Kumar    2013-11-20 16:42:49

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

Posted by Merit Campus    2013-11-21 03:35:22

© meritcampus 2019

All Rights Reserved.

Open In App