Java program to count words starting with capital letters in given line

Simple Java program to count words starting with capital letters in given line

Code:

import java.util.Scanner;

class p83{public static void main(String args[]){

Scanner sc=new Scanner(System.in);

String s;

System.out.println("Enter a line:");

s=sc.nextLine();

int count=0;

for(String str: s.split(" ")) {

if(str.charAt(0)>=65 && str.charAt(0)<=90)

{

count++;

}

}

System.out.println("total number of words start with capital letters are :"+count);

}}

Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Java Program to Implement sorting algorithm using TCP on Server application

C++ program to perform data transformation Min-max and Z score Normalization