Write a program to count the number of words that start with capital letters

Write a program to count the number of words that start with capital letters

Write a program to count the number of words that start with capital letters

Hello friends i hope you like my previous post, in today’s post we are going discuss about Write a program to count the number of words that start with capital letters

so you have to Write a program to count the number of words that start with capital letters (we have to take string from user)

so now let’s discuss the logic, how you can implement it

you have to take string from user so you have to make use of Scanner class and store the user input in string variable “str

note : make sure you use of next() or nextline() method for scanning user input

Now create for loop and run the for loop  upto the length of the string [ Ex: for (int i = 0; i < str.length(); i++) { } ]

Now inside loop take all character of string one by one by passing for loops current index “i” in str.charAt(i) and then use java’s predefined method isUpperCase() to check whether that character is capital latter or not [ Ex: if (Character.isUpperCase(str.charAt(i))) { }]

if character is capital then increment the counter that’s all “Write a program to count the number of words that start with capital letters”  is completed [Ex: count++; ]

and in last print the counter variable using System.out.println(count);

check the program for reference which is given below the post

Check Out other post – Write a program to accept a line and check how many consonants and vowels are there in line

if you like the the way of explanation tell us in comment section you can also write the queries about this program we are defiantly going reply

share this post with your college friends so everyone can get benefit of it good bye friends see you in next post happy coding

Program As per GTU Syllabus

Program :

OUTPUT :

Write a program to count the number of words that start with capital letters

 

 

 

You May Also Like

About the Author: TheCoder

Leave a Reply

Your email address will not be published. Required fields are marked *