Search This Blog

Wednesday, 6 July 2016

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

Unit - 2

Practical 4


package pl;
import java.util.Scanner;

public class Pl {

    public static void main(String[] args) {
 
        int c=0,v=0;
        String s;
        Scanner in =new Scanner(System.in);
        System.out.println("Enter String :");
        s = in.nextLine();
        int ct=0;
        for(String str: s.split(" ")) {
        if(str.charAt(0)>=65 && str.charAt(0)<=90)
        {
            ct++;
        }
    }
    System.out.println("total  number of words start with capital letters are :"+ct);
    }
}


output:

Enter String :
Karan Gajjar kanu
total  number of words start with capital letters are :2

No comments:

Post a Comment