Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Write a Java program String to uppercase and count words startig with ‘A’

Write a program to input a sentence and convert it into uppercase and count and display the total number of words starting with a letter ‘A’.

Ans.

import java.io.; import java.util.;
class UpperCount {
public static void main(String args[ ]) {
int i, a;
Scanner sc = new Scanner(System.in);
String str, str1, str2;
System.out.prindn(“Enter sentence::”);
str = sc.nextLine();
strl = str.toUpperCaseO; ‘
str2 = “” + strl;
a = 0; ,
for (i = 0; i < = str2.1ength(); i+ +) {
if(str2.charAt(i) == ‘ ‘)
if(str2.charAt(i + 1) == ‘A’);
a+ +;
}
System.out.println(“Total number of words starting with letter ‘A’::” +a);
}
}