

InterviewSolution
Saved Bookmarks
1. |
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’.Example: Sample Input: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING. Sample Output : Total number of words starting with letter A’ = 4. |
Answer» 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); } } |
|