- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to count upper and lower case characters in a given string
In order to count upper and lower case character we have to first find weather a given character is in upper case or in lower case.For this we would take concept of ASCII value of each character in Java.
In Java as we know for each character has corresponding ASCII value so we would compare each character that it lies in the range of upper case or in lower case.In below example first convert string to a character array for easy transverse,then find weather it lies in upper case or lower case range also setted counter for upper case and lower case which get increased as character lies accordingly.
Example
public class CountUpperLower { public static void main(String[] args) { String str1 = "AbRtt"; int upperCase = 0; int lowerCase = 0; char[] ch = str1.toCharArray(); for(char chh : ch) { if(chh >='A' && chh <='Z') { upperCase++; } else if (chh >= 'a' && chh <= 'z') { lowerCase++; } else { continue; } } System.out.println("Count of Uppercase letter/s is/are " + upperCase + " and of Lowercase letter/s is/are " + lowerCase); } }
Output
Count of Uppercase letter/s is/are 2 and of Lowercase letter/s is/are 3
- Related Articles
- C# program to count upper and lower case characters in a given string
- Python program to count upper and lower case characters without using inbuilt functions
- Count upper and lower case characters without using inbuilt functions in Python program
- Program for converting Alternate characters of a string to Upper Case.\n
- C program to convert upper case to lower and vice versa by using string concepts
- MySQL Query to change lower case to upper case?
- Java Program to check whether the entered character a digit, white space, lower case or upper case character
- Java String to Lower Case example.
- How to convert Lower case to Upper Case using C#?
- How to convert Upper case to Lower Case using C#?
- Java program to count words in a given string
- How to transform List string to upper case in Java?
- Convert vowels from upper to lower or lower to upper using C program
- Convert a C++ String to Upper Case
- Java program to delete duplicate characters from a given String

Advertisements