string in java
Question:
WAP to accept a string and count total number of uppercase and lowercase characters in a string.
💡 Solutions (1)
Super Admin
AdminFeb 09, 2026 at 07:19
upvotes
import java.util.Scanner; class Count_Upper_Lower { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter a string: "); String str = scanner.nextLine(); int upperCount = 0; int lowerCount = 0; for (int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if (Character.isUpperCase(ch)) { upperCount++; } else if (Character.isLowerCase(ch)) { lowerCount++; } } System.out.println("Number of uppercase letters: " + upperCount); System.out.println("Number of lowercase letters: " + lowerCount); } }
Want to add your solution? Login to contribute!
💬 Comments (0)
Login to post comments
No comments yet
Be the first to comment!