You are viewing a single comment's thread. Return to all comments →
what wrong in this code ? public static void main(String[] args) {
Scanner scanner = new Scanner(System.in); int n = Integer.parseInt(scanner.nextLine());; String regex = "\\b(\\w+)(?:\\s+\\1\\b)+"; Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE); while (n > 0) { String input = scanner.nextLine(); Matcher matcher = pattern.matcher(input); String resultTmp = matcher.replaceAll("$1"); System.out.println(resultTmp); n--; } scanner.close(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Java Regex 2 - Duplicate Words
You are viewing a single comment's thread. Return to all comments →
what wrong in this code ? public static void main(String[] args) {