hi everyone,

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

any idea how to achieve this ?

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;
       char[] vowel= {'a','e','i','o','u','A','E','I','O','U'};
        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);

Edited by peter_budo: Do not use CODE SNIPPET to posts questions! Use Discussion Thread

6 Years
Discussion Span
Last Post by stultuske

What do you men by "find a vowel"? Maybe you can give a sample input and output to illustrate what you mean?
In you existing code the array vowel is a complete mystery - you fill it full of vowels, but then you just use its last element to hold a copy of each char from the input string so you can test them. Then you print the array - why? And what's the point of in.contains(in) - that's a tautology - it must always be true.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.