ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2019 ICSE Computer Science Paper



Share with a Friend

Solved 2019 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Count Letters in a Sentence Program - ICSE 2019 Computer Science

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.

import java.util.Scanner; class Starting{ public static void main(String[] args){ Scanner in = new Scanner(System.in); System.out.print("Enter the sentence: "); String s = in.nextLine().toUpperCase(); int count = 0; for(int i = 0; i < s.length(); i++){ char ch = s.charAt(i); if(i == 0 || s.charAt(i - 1) == ' '){ if(ch == 'A') count++; } } System.out.println("Words starting with letter 'A' = " + count); } }

Output

 
 OUTPUT : 
Enter the sentence: ADVANCEMENT AND APPLICATION OF INFORMATION TECHNOLOGY ARE EVER CHANGING.
Words starting with letter 'A' = 4