Computer Science, asked by PranathP, 29 days ago

Write a program in Java to input a string and count the number of words starting with an uppercase alphabet. Also, display the count.​

Answers

Answered by AshStyles
6

import java.util.Scanner;

class Idkanything

{

public static void main (String args [])

{

Scanner sc = new Scanner (System.in);

System.out.println("Enter a String.");

String s = sc.nextLine();

String str = s.trim();

str = " " + str;

int len = str.length();

int count = 0;

for(int i=0; i<=len-2; i++)

{

char ch1 = str.charAt(i);

char ch2 = str.charAt(i+1);

if(ch1==' ' && ch2>='A' && ch2<='Z')

count++;

}

System.out.println("Count:"+count);

}

}

Attachments:
Similar questions