Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: get vowel character from strings

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default get vowel character from strings

    Hi everyone,

    A title said all. i need actually to find a vowel(a,e,i,o,u) in a string.
    my code counts how many vowels are in the string that's fine but i need to find a vowel character too..

    any idea how to achieve this ?


    Here is my code...

    import java.io.*;
    import java.lang.*;
    public class VowelsExample {
     
    public static void main(String[] args) throws IOException {
    BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
     
    int count = 0;
    int i;
     
    System.out.println("Enter a string :");
    String in = input.readLine();
     
    for (i=0; i<in.length(); i++){
    vowel[in.length()] = in.charAt(i);
    if(vowel[in.length()]=='a' || vowel[in.length()]=='A' || vowel[in.length()]=='e' || vowel[in.length()]== 'E' || vowel[in.length()]=='i' || vowel[in.length()]=='I' || vowel[in.length()]=='o' || vowel[in.length()]=='O' || vowel[in.length()]=='u' || vowel[in.length()]=='U')
    count ++;
    }
     
    System.out.println("total vowels are : " +count);
     
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: get vowel character from strings

    What do you mean by find a vowel? Return its position? Return which vowel it was? What if there are more than one?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: get vowel character from strings

    exactly , if i enter a string like "Hello"

    count will tell me there are 2 vowels and
    it should tell the vowels are "e o".

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: get vowel character from strings

    Okay, so where are you stuck? What have you tried? How would you do this with a piece of paper and a pencil, without a computer?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: get vowel character from strings

    There are syntax errors in your program. What is vowel?
    Also, see String tutorials to solve your problem. There are bunch of functions provided in String that might help you.

Similar Threads

  1. Do While loop + switch, Vowel Count
    By mwardjava92 in forum Loops & Control Statements
    Replies: 3
    Last Post: November 9th, 2011, 11:46 AM
  2. Help with Character arrays
    By shanklove in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 6th, 2010, 12:56 PM
  3. [SOLVED] Unknown Character
    By aussiemcgr in forum Java Theory & Questions
    Replies: 19
    Last Post: September 1st, 2010, 05:22 PM
  4. [SOLVED] last character position
    By nasi in forum AWT / Java Swing
    Replies: 2
    Last Post: May 1st, 2010, 05:31 AM
  5. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM