The Artima Developer Community
Sponsored Link

Java Buzz Forum
How to count Vowels and Consonants in Java String Word

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Javin Paul

Posts: 440
Nickname: javinpaul
Registered: Jan, 2012

Javin Paul is Java Programmer working on Finance domain.
How to count Vowels and Consonants in Java String Word Posted: Nov 19, 2013 11:20 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by Javin Paul.
Original Post: How to count Vowels and Consonants in Java String Word
Feed Title: Java67
Feed URL: http://java67.blogspot.com/feeds/posts/default?alt=rss
Feed Description: Java and technology tutorials, tips, questions for all programmers.
Latest Java Buzz Posts
Latest Java Buzz Posts by Javin Paul
Latest Posts From Java67

Advertisement
Java Program to count Vowels and Consonants in a word using JavaIn this article, we will take on a popular programming exercise of counting vowels in a word. You need to write a Java program to count how many vowels in a String, which is entered from command prompt. It's similar to program of counting occurrence of characters in a String, in fact it's a special case, where you need to count occurrences of all vowels, which includes five characters a, e, i, o and u. We will further use Scanner to get input from user, as shown in this article. Though I have put down all code inside main method for quick testing, if you are asked to write this program as part of your homework or during interview, better writing a method called public int countVowels(String word) and put logic of counting vowels there. That's a better coding style than writing everything inside main method. By the way, you can also use this logic to count number of consonants in a Java String. What you need to do is first count number of vowels and then subtract those characters from length of String, but remember this will only work if your String contains only alphabetic words, if it contains special character like @, _, | or numbers like 1,2,3 etc, than it will not work. In that case you need to extend your logic to only count consonants, by extending your switch case to include rest of 21 characters from English alphabets.
Read more ยป

Read: How to count Vowels and Consonants in Java String Word

Topic: Embedding Maven Previous Topic   Next Topic Topic: Modern Component Design with Spring


Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2014 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us