Aim :- Write a Java Program to Count the Number of Words That Starts With Capital Letters.
Java Program :
import java.util.*;
import java.util.Scanner;
class j5_5{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
String str=new String();
System.out.println("\nEnter String: ");
str=s.nextLine();
int count=0;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)>=65 &&str.charAt(i)<=90)
{
System.out.println("Capital Letter : "+str.charAt(i));
count++;
}
}
System.out.println("Total Number Of Words : "+count);
}
}
Output :
0 Comments