What is the output of the following Java program A16?

Description:

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  
}}  

Solution:

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.

0 answers