Skip to content
October 7, 2013 / TDS Software

Java Q&A

Write a Java program to read a sentence which contains more than 10 words as a keyboard
input and to find the number of words in the sentence that starts with letter ‘i’. You must
use class StringTokenizer to break the sentence into words. Save your answer as




import java.util.StringTokenizer;
class Question12{
public static void main(String[] args) {
String inp =””;
BufferedReader bf = new BufferedReader (new InputStreamReader (;
System.out.print(“Enter a Sentence : “);
inp = bf.readLine();

}catch (IOException e){

StringTokenizer st2 = new StringTokenizer(inp, ” “);
int count = 0;
while (st2.hasMoreElements()) {
String s = st2.nextElement().toString();
if (s.charAt(0)==’i’){
System.out.println(“Number of words starting with ‘i’ : ” + count );


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: