Menu
Topics Index
...
`

Regular Expression


If you need explanation Read this topic

If you need Answer Take test on this topic

Regular Expression
What is the output of the following program?
import java.util.regex.*;

public class RegularEx {
    public static void main(String... arg) {
        Pattern pattern = Pattern.compile("M+", 5);
        Matcher matcher = pattern.matcher("M Merit Match MM m mM");
        while (matcher.find())
            System.out.print(matcher.group() + " ");
    }
}

A. M M M MM M
B. M M M MM m mM
C. M M M MM mM
D. M Merit Match MM m mM
E. PatternSyntaxException
Topic: Java Regular Expression

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 E variable "pattern " not initialized

Posted by Adithya Aleti    2014-04-18 03:40:35


Ans is A as pattern is M and checks whether it matches with matcher("M Merit Match MM m mM") it it matches it prints M so ans is A

Posted by Naga Sinst    2014-04-18 03:43:02


ans is A,since matcher class returns 5 pattern sequences that is one or more M's

Posted by Raviteja Daggupati    2014-04-18 06:17:37


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

Posted by Merit Campus    2014-04-21 04:13:21


© meritcampus 2019

All Rights Reserved.

Open In App