Jump to content


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.

Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.


If only one vowel is entered in the string, then that vowel should be diplayed on console

  • Please log in to reply
2 replies to this topic

#1 abcd_1


  • Members
  • 91 posts
  • Local time:09:14 AM

Posted 25 July 2009 - 01:36 PM


I am a new bie in programming.

The answer for my question may look very simple to you.

This my current code.
import java.lang.String;
import java.io.*;
import java.util.*;

public class CountVowels {
	public static void main(String args[]) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Enter the String:");
		String text = bf.readLine();
		int count = 0;
		 char c='a';

		for (int i = 0; i < text.length(); i++) {
			 c = text.charAt(i);
			if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
		if (count == 1)
			System.out.println("there is only one vowel in the string you entered and that is --------");
		System.out.println("There are" + " " + count + " " + "vowels");

The requirement is , when i run this program giving the string "abcd"(excluding quotes). the program should give me the output as
"there is only one vowel in the string you entered and that is a"

Please suggest me the required changes that are to be made to the code.


BC AdBot (Login to Remove)


#2 groovicus


  • Security Colleague
  • 9,963 posts
  • Gender:Male
  • Location:Centerville, SD
  • Local time:09:44 PM

Posted 25 July 2009 - 02:18 PM

If the character is a vowel, then you need to set the value of 'c' to whatever value that is.

For example:

if(charAt(i) == 'a') {
   c = charAt(i));

Always use braces in if statements, even if there is only one statement inside. From a maintenance standpoint, it will prevent simple errors later.

To get your program to print out the value of c, you just need to print it out, just like you would do if you were printing out the number of vowels you found.

#3 Romeo29


    Learning To Bleep

  • Members
  • 3,194 posts
  • Gender:Not Telling
  • Location:
  • Local time:10:44 PM

Posted 26 July 2009 - 06:44 PM

You forgot to print the vowel in this line :

System.out.println("there is only one vowel in the string you entered and that is --------");

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users