Switch to Dark Mode

Consider the following code snippet. What will be the output of this code?

Last Updated : Apr 25, 2025
Discuss
Comments

Consider the following code snippet. What will be the output of this code?

import java.util.regex.*;

public class Main {
    public static void main(String[] args) {
        String regex = "a*b";
        String input = "aaab";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);
        System.out.println(matcher.matches());
    }
}
A

true

B

false

C

aaab

D

Compile-time error

Share your thoughts in the comments