Words With Uppercase Letters
Write a program to print the words of a string that starts with an uppercase letter.
/* WAP to print the words of a string that starts with an uppercase letter. */
import java.io.*;
class StringQ08
{
public static void main(String arg[])throws IOException
{
int i, l, ucw;
String str;
char ch;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a string : ");
str=br.readLine().trim();
str = " "+str;
l = str.length();
// To count words starting with uppercase letter
ucw = 0;
for(i=0;i < l;i++){
ch = str.charAt(i);
if(ch == ' '){
char ch1 = str.charAt(i+1);
if(ch1 >= 'A' && ch1 <= 'Z')
ucw++;
}
}
System.out.println("No of words starting with uppercase letter: "+ucw);
}//end of main
}//end of class
Have something to say? Log in to comment on this post.
0 comments