Write a program to accept a three letter word as an input from the message, Expression Matched, if the world starts with ,"a","b","c", and ends with, "at".Solution
import java . util . regex . Matcher;
imort java . util . regex . Pattern;
public class TestRegx {
public static void main (String [] args) {
Scanner sc = new Scanner (System . in);
String input;
System.out..print ("Enter the string: ");
input = sc . next ();
Pattern myPattern = Pattern . compile (" [abc] at");
Matcher myMatcher = myPattern . matcher (input);
boolen myBoolen = myMatcher . matches ();
if (myBoolen) {
System.out.println ("Expression is Matched");
} else {
System.out.println ("Expression Not Matched");
}
}
}
No comments:
Post a Comment