We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
something is wrong, not able to output anything
import java.io.;
import java.util.;
public class Solution {
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
String regex = "\\b(\\w+)\\b(?:\\s+\\b\\1\\b)+";
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Scanner scan = new Scanner(System.in);
int count = scan.nextInt();
scan.nextLine();
for(int i = 0; i< count; i++){
String s = scan.nextLine();
System.out.println(s);
String smallCase = s.toLowerCase();
Matcher matches = p.matches(smallCase);
String result = matches.replaceAll("$1");
System.out.println(result);
}
}
}
Cookie support is required to access HackerRank
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 →
something is wrong, not able to output anything import java.io.; import java.util.;
public class Solution {
}