As a new programmer, I am working on a problem that tells me to turn an array of 10 ints into a formatted string phone number that looks like this: (999) 999-9999. I am getting an error/issue with Matcher.
I tried to turn the array of ints into a single string, and then I tried to create a matcher and capturing groups to split the number into the first 3 numbers, the second three, and the last four. I keep getting errors and I do not know what exactly is going wrong. This is what my code looks like:
`import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
public class Kata {
private final static String pattern = "(?<first>[0-9][0-9][0-9])+(?<second>[0-9][0-9][0-9])+(?<third>[0-9][0-9][0-9][0-9])";
private final static Pattern paddy = Pattern.compile(pattern);
public static Matcher match(String text){
var mitch = paddy.matcher(text);
mitch.find();
return mitch;
}//end method
public static String createPhoneNumber(int[] numbers) {
int space = 1;
return String.format("(%s)" + space + "%s-%s", partOne(numbers), partTwo(numbers), partThree(numbers));
}//end method
public static String partOne(int[] numbers){
String phoneNumber = numbers.toString();
return match(phoneNumber).group("first").strip();
}//end method
public static String partTwo(int[] numbers){
String phoneNumber = numbers.toString();
return match(phoneNumber).group("second").strip();
}//end method
public static String partThree(int[] numbers){
String phoneNumber = numbers.toString();
return match(phoneNumber).group("third").strip();
}//end method
}`