The question were asked mainly from core java related collections, oops concepts. there is one coding question : Print the number of repeated words in a setence
Sigiloso
import java.util.*; public class RepeatedWordsCounter { public static int countRepeatedWords(String sentence) { // Convert sentence to lowercase and remove punctuation sentence = sentence.toLowerCase().replaceAll("[^a-z\\s]", ""); // Split into words String[] words = sentence.split("\\s+"); // Use a HashMap to count word frequencies Map wordCount = new HashMap(); for (String word : words) { if (!word.isEmpty()) { wordCount.put(word, wordCount.getOrDefault(word, 0) + 1); } } // Count how many words are repeated int repeated = 0; for (int count : wordCount.values()) { if (count > 1) { repeated++; } } return repeated; } public static void main(String[] args) { String sentence = "This is a test. This test is only a test."; int result = countRepeatedWords(sentence); System.out.println("Number of repeated words: " + result); } }