0 votes
in JAVA by
What is the output of the following Java program?

import java.util.regex.*;  

class RegexExample2{  

public static void main(String args[]){  

System.out.println(Pattern.matches(".s", "as")); //line 4  

System.out.println(Pattern.matches(".s", "mk")); //line 5   

System.out.println(Pattern.matches(".s", "mst")); //line 6  

System.out.println(Pattern.matches(".s", "amms")); //line 7  

System.out.println(Pattern.matches("..s", "mas")); //line 8  

}}

1 Answer

0 votes
by

Output

true

false 

false

false 

true

Explanation

line 4 prints true since the second character of string is s, line 5 prints false since the second character is not s, line 6 prints false since there are more than 3 characters in the string, line 7 prints false since there are more than 2 characters in the string, and it contains more than 2 characters as well, line 8 prints true since the third character of the string is s.

Related questions

0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
+3 votes
asked May 13, 2021 in JAVA by rajeshsharma
...