You are viewing a single comment's thread. Return to all comments →
Same with me
import java.util.Scanner; public class DuplicateWords { public static void main(String[] args) { Scanner in = new Scanner(System.in); int numSentences = Integer.parseInt(in.nextLine()); while (numSentences-- > 0) { String input = in.nextLine(); String[] arr = input.split(" "); String[] res = new String [arr.length]; int i = 0; for(String item : arr ){ boolean found = false; for (String term : res ) if ( term != null && term.equalsIgnoreCase(item)) found = true; if ( found == false ) res[i] = item; i++; } input = ""; for (String term : res ) if (term != null) input += term + " "; System.out.println(input); } in.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 →
Same with me