β Java Program: Count Vowels and Numbers
import java.util.Scanner;
public class VowelAndNumberCounter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Take input from the user
System.out.print(“Enter a string: “);
String input = scanner.nextLine();
// Initialize counters
int vowelCount = 0;
int numberCount = 0;
// Convert input to lowercase to simplify vowel check
input = input.toLowerCase();
// Loop through each character
for (int i = 0; i < input.length(); i++) {
char ch = input.charAt(i);
// Check if the character is a vowel
if (ch == ‘a’ || ch == ‘e’ || ch == ‘i’ || ch == ‘o’ || ch == ‘u’) {
vowelCount++;
}
// Check if the character is a digit
if (Character.isDigit(ch)) {
numberCount++;
}
}
// Output the results
System.out.println(“Number of vowels = ” + vowelCount);
System.out.println(“Number of numbers = ” + numberCount);
}
}
β Sample Input and Output
Input:
Hello123 World
Output:
Number of vowels = 3
Number of numbers = 3