Computer Science, asked by ayandutta2029, 11 months ago

write a programe in java to count the number of lower class and upper class and special character and digits present in a user given string​

Answers

Answered by BrainlyTech
1

                                         This is a C++ Script

 C++ program to count the uppercase,  

 lowercase, special characters  

 and numeric values  

#include<iostream>  

using namespace std;  

   Function to count uppercase, lowercase,  

   special characters and numbers  

void Count(string str)  

{  

int upper = 0, lower = 0, number = 0, special = 0;  

for (int i = 0; i < str.length(); i++)  

{  

 if (str[i] >= 'A' && str[i] <= 'Z')  

  upper++;  

 else if (str[i] >= 'a' && str[i] <= 'z')  

  lower++;  

 else if (str[i]>= '0' && str[i]<= '9')  

  number++;  

 else

  special++;  

}  

cout << "Upper case letters: " << upper << endl;  

cout << "Lower case letters : " << lower << endl;  

cout << "Number : " << number << endl;  

cout << "Special characters : " << special << endl;  

}  

// Driver function  

int main()  

{  

string str = "#lEaKs02pLr@rEeSs05";  

Count(str);  

return 0;  

}  

Below ↓

Input : #lEaKs02pLr@rEeSs05

Output :  

Upper case letters : 5

Lower case letters : 8

Numbers : 4

Special Characters : 2

Input : *lEakS8EaStS*

Output :

Upper case letters : 5

Lower case letters : 5

Numbers : 1

Special Characters : 2

Similar questions