EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

βœ… 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

 

 

Java practice programs for leetcode

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer