I have written this code to determine duplicate words in the string.
but its not working.
plz help....
i am getting error in line 19.
import java.util.*;
import java.util.Scanner;
public class duplicate {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int n = input.nextInt();
System.out.println ("Input length of array:");
String[] a = new String[n];
for (int i = 0; i < n; i++)
{
System.out.println ("Input a[ " + i +"] :" );
a[i] = new String(input.nextLine());
}
Set<String> s = new HashSet<String>();
for (int i=0;i<n;i++ )
if (!s.add(a))
System.out.println("Duplicate detected: " + a);
System.out.println(s.size() + " distinct words: " + s);
}
}