Accenture Accenture Primer Practice Question
Predict the output What will be the output for the given code snippet Startprogram Import java.util.regex; Public class Main{ public static void main(String args[]) { String s=”ABC”; Pattern p=Pattern.compile(s); String r=”ABCABCABCABC”; Matcher m=p.matcher(r); System.out.println(m.lookingAt()); } } endprogramAnswer options
A
true
B
false
C
ABC
D
0
Correct answer: true
Explanation
Matcher.lookingAt() attempts to match the pattern at the beginning of the input. The pattern 'ABC' matches the start of 'ABCABCABCABC', so it returns true.