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...
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);
}
}
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?
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".
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?
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.