Practical 6


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

JAVA Code :-

import java.lang.*;
import java.io.*;
import java.util.*;

class pra6
{
  public static void main(String args[])
  {
     int len,i=0,count=0;
     char ch[]=new char[25];

     String str=new String();
     Scanner s=new Scanner(System.in);

     System.out.print("Enter your string: ");
     str=s.nextLine();
    
     len=str.length();
     ch=str.toCharArray();
    
     if(ch[0]>=65 && ch[0]<=90)
             count++;

     for(i=1;i<len;i++)
     {
        if(ch[i]==' ')
         {
                if(ch[i+1]>=65 && ch[i+1]<=90)  
                           count++;
         }
      }

       System.out.println("\nNo. of words starting with captical is "+count);
   }
}

Output:-



No comments:

Post a Comment

Programs

Home Aim:- Write a program to convert rupees to dollar. (60rupees=1 dollar). Aim:- Write a program that calculate percentage marks...