Java Write Program Determines Prints Number Duplicate Words Sentence Treat Uppercase Lower Q37052649

in java Write a program that determines and prints the number ofduplicate words in a sentence. Treat uppercase and lowercaseletters the same. Ignore punctuation.


Solution


import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class WordFreq {
   public static void main(String[] args) {
       Scanner sc = newScanner(System.in);
       System.out.println(“Enter sentense:”);
       String str = sc.nextLine();
       Map<String, Integer> map =new HashMap<>();
       String words[] = str.split(“”);
       for (String w : words) {
           w =w.toLowerCase();
           Integer n =map.get(w);
           n = (n == null)? 1 : ++n;
           map.put(w,n);
       }
       int count = 0;
       for

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.