program to determine number of duplicates in a sentence
Posted
by bhavna raghuvanshi
on Stack Overflow
See other posts from Stack Overflow
or by bhavna raghuvanshi
Published on 2010-06-17T06:00:00Z
Indexed on
2010/06/17
6:03 UTC
Read the original article
Hit count: 161
java
public class duplicate
{
public static void main(String[] args)throws IOException
{
System.out.println("Enter words separated by spaces ('.' to quit):");
Set<String> s = new HashSet<String>();
Scanner input = new Scanner(System.in);
while (true)
{
String token = input.next();
if (".".equals(token))
break;
if (!s.add(token))
System.out.println("Duplicate detected: " + token);
}
System.out.println(s.size() + " distinct words:\n" + s);
} }
my program detects and prints duplicate words but i need to print the number of duplicate words also. pls help me do it.
© Stack Overflow or respective owner