import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class DuplicateString { public static boolean hasDuplicateWords(String sentence) { String[] words = sentence.split(" "); Set seenWords = new HashSet<>(); for (String word : words) { if (!seenWords.add(word)) { return true; } } return false; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a sentence:"); String sentence = scanner.nextLine(); if (hasDuplicateWords(sentence)) { System.out.println("The sentence contains duplicate words."); } else { System.out.println("The sentence does not contain duplicate words."); } } }