I want to count total number of duplicate word or repeating word in a sentence. Here I am able to print the words but not able to count those words.

```
import java.util.*;
public class Duplicate {  

    public static void main(String[] args) {  

        String input = "Big black bug bit a big black dog on his big black nose";  
        //Scanner scanner = new Scanner(System.in);
         //System.out.println("Enter the sentence");

        //String input = scanner.nextLine();

        int count; 
        int counter=0;

        //Converts the string into lowercase  
        input = input.toLowerCase();  

        //Split the string into words using built-in function  
        String words[] = input.split(" ");  

        System.out.println("Duplicate words in a given string : ");   
        for(int i = 0; i < words.length; i++) {  
            count = 1;  
            for(int j = i+1; j < words.length; j++) {  
                if(words[i].equals(words[j])) {  
                    count++;  
                    //Set words[j] to 0 to avoid printing visited word  
                    words[j] = "0";  
                    counter=counter+1;

                }  
            }  

            //Displays the duplicate word if count is greater than 1  
            if(count > 1 && words[i] != "0")  {
                System.out.println(words[i]);
            }

        } 

        System.out.println("Total Duplicate words in a given string : " +counter);
}  
}

```

I expect output :--

> 
> Duplicate words in a given string : big black
> 
> 
> Total Duplicate words in a given string : 2
> 
> 
> 

The output is coming like :

> 
> Duplicate words in a given string : big black
> 
> 
> Total Duplicate words in a given string : 10
> 
> 
> 

Total count is showing 10 instead of 2.