Count Lowercase Letters
Count number of lowercase letters in a string.
BeginnerTopic: Module 4: String Programs
Java Count Lowercase Letters Program
This program helps you to learn the fundamental structure and syntax of Java programming.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string: ");
String s = sc.nextLine();
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (Character.isLowerCase(s.charAt(i))) {
count++;
}
}
System.out.println("Lowercase letters: " + count);
sc.close();
}
}Output
Enter a string: Hello Lowercase letters: 4
Understanding Count Lowercase Letters
We use Character.isLowerCase on each character.
Note: To write and run Java programs, you need to set up the local environment on your computer. Refer to the complete article Setting up Java Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your Java programs.