Java program of Count repeating words

Question:-

In a given sentence, find the maximum repeated word and print the same.(Assume that all the characters are in lower case)

Sample Input 1:

java is programming language and an object oriented language

Sample Output1:

language

Sample Input2:

suvi felt happy because suvi saw that the others were happy

Sample Output2:

suvi

happy

Sample Input2:

he went out yesterday

Sample Output2:

No repetition of words

Code:-

Main.java

import java.util.*;
public class Main {
    public static void main (String[] args) {
        Scanner sc=new Scanner(System.in);
        String str[]=sc.nextLine().split(" ");
        
        int len=str.length;
        int flag=0;
        for(int i=0;i<len;i++)
        {
            for(int j=(i+1);j<len;j++)
            {
                if((str[j]).equals(str[i]))
                {
                    System.out.println(str[j]);
                    flag++;
                    break;
                }
            }
        }
        if(flag==0)
        {
            System.out.println("No repetition of words");
        }
    }
}

Recommended:-

  1. Array square
  2. Generate number using odd digits
  3. Alternate Number Difference
  4. Next Greatest number
  5. Mark Comparison
  6. Print the characters in descending order
  7. Vowels in a fishBowl
  8. Least offer
  9. Ascending and descending order
  10. Mail Domain
  11. Count repeating words
  12. Sentence – Convert to upper and lower
  13. Count consecutive repeating characters
  14. Zig zag Array
  15. Pass and Fail Count
  16. Search a Course
  17. Average and Grade Calculation
  18. String – Find and replace the character (first occurrence)
  19. Sort the first and second half of an array
  20. Retail Shop
  21. Palindrome
  22. Numerology
  23. InitCap
  24. Array Compatiblilty
  25. Sum of the maximum and the minimum element
  26. String Concatenation
  27. Find Average Age
  28. Login
  29.  

Leave a Comment

Your email address will not be published. Required fields are marked *

x