C Program
void countCase(char *s) { int u = 0, l = 0; while (*s) { if (*s >= 'A' && *s <= 'Z') u++; else if (*s >= 'a' && *s <= 'z') l++; s++; } printf("Upper: %d\nLower: %d", u, l); }
C Output
Upper: 5 Lower: 5
C++ Program
void countCase(string s) {
int u = 0, l = 0;
for (char c : s) {
if (isupper(c)) u++;
else if (islower(c)) l++;
}
cout << "Upper: " << u << "\nLower: " << l;
}
C++ Output
Upper: 5 Lower: 4
JAVA Program
void countCase(String s) { int u = 0, l = 0; for (char c : s.toCharArray()) { if (Character.isUpperCase(c)) u++; else if (Character.isLowerCase(c)) l++; } System.out.println("Upper: " + u + "\nLower: " + l); }
JAVA Output
Upper: 2 Lower: 10
Python Program
def count_case(s): u = sum(1 for c in s if c.isupper()) l = sum(1 for c in s if c.islower()) print("Upper:", u, "\nLower:", l)
Python Output
Upper: 3 Lower: 3
In-Depth Explanation
Example
Suppose the input is "HeLLoWorld".
Traversing the string, we:
Count 'H', 'L', 'L', 'W' and 'D' as upper case → 5
Count 'e', 'o', 'o', 'r' and 'l' as lower case → 5
We get a balanced case string — handy when checking text format or normalizing inputs.
Real-Life Analogy
Suppose you're looking at names typed in a form. Some individuals can type "john", some "JOHN", and others "John". You might need to ensure the number of uppercase vs lowercase characters to:
Check for proper formatting (e.g., title case)
Enforce consistent naming conventions
Prevent yelling (ALL CAPS) in user interfaces
This verification is typically performed during form validation, user input sanitization, or even data normalization operations.
Why It Matters
This trivial character categorization task illustrates how to:
Traverse strings
Use conditional checks (isupper, islower)
Keep independent counts depending on the character type
It also introduces some basic character processing, which is the foundation of most string algorithms — including encryption, formatting, and parsing.
Understanding how to process and separate cases is important when:
Sorting strings
Processing passwords
Normalizing user input
What You Learn from This
How to detect character types using ASCII values or built-in functions
Practical application of counters and conditions
Real-world significance of character-level data cleaning
Base for more complex string tasks such as case conversion, validation, or formatting
These are minor but fundamental skills required in data cleansing, text analytics, and input management systems.
Interview Relevance and Real Projects
This task is commonly employed during interviews to test:
String traversing capability
Knowledge of character handling
Clean conditional logic
It is also likely to be blended with:
Digit count
Special character count
Word classification logic
In real-life apps, this logic is encountered in:
Input validation forms (e.g., name fields)
Password strength testers (at least 1 uppercase & 1 lowercase needed)
Chat filters and text formatters
SEO-Optimized Explanation
Enumerating uppercase and lowercase characters in a string with C, C++, Java, and Python is a simple but useful exercise that enhances your character-processing logic. This program illustrates how to recognize alphabet case with loops or intrinsic functions and enumerate them separately. It is widely applied in form validation, input sanitizing, and password policy checks. Understanding how to verify the presence of uppercase and lowercase letters equips you with skills that are relevant to coding interviews, enhances your reasoning for text preprocessing in actual applications, and enables you to develop strong foundations in string manipulation. Such an exercise is crucial in system-level programming as well as front-end user data management.
Social Plugin