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[]) { Pattern p=Pattern.compile(“\\d”); String test=”India123”; Matcher m=p.matcher(test); If(m!null) { System.out.println(m.find()); System.out.println(m.matches()); } } } endprogramAnswer options
A
true
true
B
false
true
C
true
false
D
false
false
Correct answer: true false
Explanation
Pattern \d on string 'India123': m.find() searches for a digit anywhere in the string — 'India123' contains digits, so returns true. m.matches() requires the entire string to match \d — 'India123' does not fully match a single digit, so returns false. Output: true\nfalse.