DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

How To Read The Words That Are Repeated?

02.21.2011
| 2878 views |
  • submit to reddit
        // Reads & reports the number of words that are repeated in the sentence!

public class stutter
{

 public static void main (String[] args)
 {
 
  String str = " ";
  String[] words = str.split (" ");
  for (int i=0; i<words.length; i++)
 
	{
      if(words[i].equals(words[i-1]))     //Stuttered
      System.out.println (words[i]);   
    	}
 }
}