ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2023 ICSE Computer Science Paper



Share with a Friend

Solved 2023 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Print Number of Digits, Alphabets and Special Characters Program - ICSE 2023 Computer Science

Question 6

Define a class to accept a string and print the number of digits, alphabets and special characters in the string.

Example: S = “KAPILDEV@83”


Output:

Number of digits = 2
Number of alphabets = 8
Number of special characters = 1

import java.util.Scanner; class Overload{ public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter the string: "); String s = in.nextLine(); int digits = 0; int alphabets = 0; int special = 0; for(int i = 0; i < s.length(); i++){ char ch = s.charAt(i); if(Character.isLetter(ch)) alphabets++; else if(Character.isDigit(ch)) digits++; else special++; } System.out.println("Number of digits = " + digits); System.out.println("Number of alphabets = " + alphabets); System.out.println("Number of digits = " + special); } }

Output

 
 OUTPUT 1: 
Enter the string: KAPILDEV@83
Number of digits = 2
Number of alphabets = 8
Number of digits = 1


 OUTPUT 2: 
Enter the string: MAHINDERSINGHDHONI@2011
Number of digits = 4
Number of alphabets = 18
Number of digits = 1