Hey so I dont want someone to just show me the code, but I've been struggling to get this to work for hours. I need to write a program that finds all the words with consecutive vowels in them... this is what I have so far...
-we are given a string array called words of all the words in the dictionary from a linked text file
-i changed the string array to char array so it would be easier to check each letter for being a vowel and then I set my vowels as a string and converted them to a char array....from here I made 3 int variable represent the index of the char, vowel, and word in their respective arrays...i believe my code is right up to here....
now how could i go through each word and check if it contain first an a, then an e, ,i,o,u and if it contains all 5 in that order (it doesnt matter if other vowels are inbetween for example sacrilegious works) then i would want to add it to the list of words that fits the category (named foundWords) any ideas?

import java.io.*;
import java.util.*;

public class FindStrangeWords {
	public static void main (String[] argv)
	{
		myTests ();
		mainTest ();
	}

	static void myTests ()
	{
		// INSERT YOUR TEST CODE HERE.
	}


	static void mainTest ()
	{
		String[] words = WordTool.getDictionary ();
		findConsecVowelWords (words);
	}

	static void findConsecVowelWords (String[] words)
	{
		int foundWords = 0;
		int vowelCount = 0;
		String vowelCheck = "aeiou";
		char[] vowel = vowelCheck.toCharArray();
		for(int i=0;i<words.length;i++){
			char[] letters = words[i].toCharArray();
			for(int k=0;k<letters.length;k++){
				for(int j=0;j<vowel.length;j++){
					if (vowel[j] != letters[k]){
						vowelCount=0;
					}
					else { 
						vowelCount++;
					}
					if(vowelCount>4){
						foundWords++;
						vowelCount=0;
						System.out.println(words[i]);
						System.out.println("Word Found!");
						System.out.println(foundWords);
					}
				}
			}
		}
	}
}

Recommended Answers

All 5 Replies

How about using flags for every pattern that occurs. Since you want 'aeiou' order to be maintained , you can have 5 flags for ,say a, ae , aei ,aeio , aeiou. Only if aFlag is true,aeFlag can be true. Only if ae flag is true and you encounter an i, then set aeiFlag to true and so on. When aeiouFlag is set means you got your word. Just an idea, i am not sure if its the best one to follow.

also see in you first for statement you are declaring the char[] letters within this statement, which can bring alot of problems so its not recommended rather declare it outside the for statement

For each word:
int nextVowel = 0;
Loop through the word
look for vowel[nextVowel]. If you find it, nextVowel++ and continue looping thru the word
If nextVowel gets to 5 the word has all 5 vowels in order

my head hurts and im starting to think its impossible. I believe i need to declare the char [] letters within the first for statement because i want to increment i, which is the index of the string array...so as i increasing you move the the dictionary one at a time, and as j increasing you move through the char of each word string one a time....i need to check each word to see if it has every vowel in order

public class FindStrangeWords {
	public static void main (String[] argv)
	{
		myTests ();
		mainTest ();
	}

	static void myTests ()
	{
		// INSERT YOUR TEST CODE HERE.
	}


	static void mainTest ()
	{
		String[] words = WordTool.getDictionary ();
		findConsecVowelWords (words);
	}

	static void findConsecVowelWords (String[] words)
	{
		int i= 0;
		int foundWords = 0;
		int vowelCount = 0;
		String vowelCheck = "aeiou";
		//use string of vowels to make char array with the variable vowelCheck
		//search the entire dictionary one word at a time by incrementing i

		char[] vowel = vowelCheck.toCharArray();
		for(i=0;i<words.length;i++){
			char[] letters = words[i].toCharArray();
			//use string array "words" and convert to new char array "letters"
			for(int j=0;j<vowel.length;j++){
				//search each word letter by letter by incrementing k
				for(int k=0;k<letters.length;k++){
					//if the first letter does not equal the first vowel reset
					//the vote count and return the vowels index back to 0, also
					//go to the next string in the array by incrementing i
					//										System.out.println(letters[k]);
					//					System.out.println(vowel[j]);

					if (vowel[j] == letters[k]){
						vowelCount++;
					}
				}
			}
			//if the key word is found with 5 consecutive vowels, reset 
			//vowel count and print "word found"
			if(vowelCount>4){
				foundWords++;
				vowelCount=0;
				System.out.println(words[i]);
				System.out.println("Word Found!");
				System.out.println(foundWords);
			}
		}
	}
}

my head hurts and im starting to think its impossible. I believe i need to declare the char [] letters within the first for statement because i want to increment i, which is the index of the string array...so as i increasing you move the the dictionary one at a time, and as j increasing you move through the char of each word string one a time....i need to check each word to see if it has every vowel in order

public class FindStrangeWords {
	public static void main (String[] argv)
	{
		myTests ();
		mainTest ();
	}

	static void myTests ()
	{
		// INSERT YOUR TEST CODE HERE.
	}


	static void mainTest ()
	{
		String[] words = WordTool.getDictionary ();
		findConsecVowelWords (words);
	}

	static void findConsecVowelWords (String[] words)
	{
		int i= 0;
		int foundWords = 0;
		int vowelCount = 0;
		String vowelCheck = "aeiou";
		//use string of vowels to make char array with the variable vowelCheck
		//search the entire dictionary one word at a time by incrementing i

		char[] vowel = vowelCheck.toCharArray();
		for(i=0;i<words.length;i++){
			char[] letters = words[i].toCharArray();
			//use string array "words" and convert to new char array "letters"
			for(int j=0;j<vowel.length;j++){
				//search each word letter by letter by incrementing k
				for(int k=0;k<letters.length;k++){
					//if the first letter does not equal the first vowel reset
					//the vote count and return the vowels index back to 0, also
					//go to the next string in the array by incrementing i
					//										System.out.println(letters[k]);
					//					System.out.println(vowel[j]);

					if (vowel[j] == letters[k]){
						vowelCount++;
					}
				}
			}
			//if the key word is found with 5 consecutive vowels, reset 
			//vowel count and print "word found"
			if(vowelCount>4){
				foundWords++;
				vowelCount=0;
				System.out.println(words[i]);
				System.out.println("Word Found!");
				System.out.println(foundWords);
			}
		}
	}
}

sorry i see what you ment, but could you please include your WordTool class so i can test the code and see whats happening because as you have seen im not good at static analysis of code :P

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.