Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Wednesday, 25 January 2017

Java Program to find number of distinct words are there in a given sentence.....

import java.util.*;
public class Que2 {
public static void main(String args[])
{int count=1;
Scanner sc=new Scanner(System.in);
System.out.println("enter String ");
String s1=sc.nextLine();
StringTokenizer t=new StringTokenizer(s1);
HashSet h1=new HashSet();
for(int i=0;i<s1.length();i++)
{
h1.add(s1);
if(s1.charAt(i)==' ')
{
count++;
}
}
System.out.println(h1);
System.out.println(count);
}
}

No comments:

Post a Comment