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(in.contains(in));
            System.out.println(String.valueOf(vowel));
            System.out.println("total vowels are : " +count);
            
    }
}

Recommended Answers

All 2 Replies

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.

well, you can use the 'i' you use to iterate over your input, and print (at index i there's vowel <vowel>)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.