string in java

C
✅ Solved
Asked by Neelkumar Gohil Feb 03, 2026 at 05:04 Subject: Java Programming

Question:

WAP to accept a string and count total number of uppercase and lowercase characters in a string.

💬 0 Comments 💡 1 Solution(s)

💡 Solutions (1)

✅ ACCEPTED SOLUTION

Super Admin

Admin

Feb 09, 2026 at 07:19

👍 0

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); } }

👍 Login to Vote

Want to add your solution? Login to contribute!

💬 Comments (0)

Login to post comments

No comments yet

Be the first to comment!