Practical 6: Write a program to count the number of words that start with capital letters.

Program:
import java.util.*;
class practical6
{
    public static void main(String m[])
    {
        Scanner in=new Scanner(System.in);
        String s=new String();
        System.out.println("Enter a line:");
        s=in.nextLine();
        char c;
        int ct=0;
        for(int i=0;i<s.length();i++)
        {
            c=s.charAt(i);
            if(c>=65 && c<=90)
            {
                ct++;
            }
        }
        System.out.println("total  number of words start with capital letters are :"+ct);
    }
}

Output:







Comments

Popular posts from this blog

Practical 12: Refine the student manager program to manipulate the student information from files by using the BufferedReader and BufferedWriter

Practical 9 : Write an interactive program to print a string entered in a pyramid form. For instance, the string “stream” has to be displayed as follows: