Writing a code to find words with all five consecutive vowels

  • (2 Pages)
  • +
  • 1
  • 2

15 Replies - 8328 Views - Last Post: 15 August 2009 - 12:51 PM Rate Topic: -----

#1 Vychu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-October 08

Writing a code to find words with all five consecutive vowels

Post icon  Posted 28 October 2008 - 12:31 PM

I am trying to write a code that reads a text file of many words ( I got this part). Then I need to read each word and find/print those words that have all five vowels in it (in consecutive order: a,e,i,o,u). I am very confused how I would approach doing this!! please help!!!
Is This A Good Question/Topic? 0
  • +

Replies To: Writing a code to find words with all five consecutive vowels

#2 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2777
  • View blog
  • Posts: 11,750
  • Joined: 20-September 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 12:46 PM

Simply

word.matches(".*a.*e.*i.*o.*u.*");


would do it

This post has been edited by g00se: 28 October 2008 - 12:46 PM

Was This Post Helpful? 0
  • +
  • -

#3 Vychu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-October 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 12:48 PM

Is there another way to do this because I have not learned that in my class yet. For instance using a loop of some sort?
Was This Post Helpful? 0
  • +
  • -

#4 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 01:05 PM

you can split the input String into an array of Strings...then traverse through the array and check every element in the arrray
String [] x = input.split( " " ); 


this will split the input into an array of Strings..
Was This Post Helpful? 0
  • +
  • -

#5 Vychu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-October 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 01:09 PM

Ok that makes sense to me. How can I transverse through the array and check for each vowel then to make sure the vowels are in order?
Was This Post Helpful? 0
  • +
  • -

#6 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 01:20 PM

You could split the String into a character array:
char[] x = input.toCharArray();
And then loop through the char array and check for the occurence of each vowel, taking into account order. So first check for a, when that is found set a flag saying a was found, then search for b, and so on
for(int i = 0; i < x.length; i++){
   if(!aFound){
	   if(x[i] == 'a') aFound == true;
   } else if(!bFound){
	   if(x[i] == 'b') bFound == true;
//And so on


Then after the loop you can check if all the flags are true
Was This Post Helpful? 0
  • +
  • -

#7 Vychu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-October 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 01:27 PM

Thank you that was very helpful.

I am curious as to what the statement:

else if(!bFound){

does?

Also how would I go about asking to print the flagged ones with all the vowels?
Was This Post Helpful? 0
  • +
  • -

#8 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 01:34 PM

the statement:

else if(!bFound){

says that is b is not(!) yet found execute this code, bFound is a boolean variable to keep tract of whether or not the b vowel was yet found

To print the flagged ones you would have to check if all the flags were true after you went through the above loops.
So for a list of words you would loop through the list and each time you would loop through the word you are currently at whith the above loop, and after that loop you would check if all the flags were true, if they were you would print the word, if not you would move on to the next word.
Was This Post Helpful? 0
  • +
  • -

#9 Vychu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-October 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 01:45 PM

I just want to make sure I am understanding this correctly so I wrote out a mock psuedo code, please tell me if I am correct.

READ the file to get the words
DECLARE each word into a string of characters
Split the String into a character array
FOR loop to read through the character array
Check the occurrence of each vowel
Start IF a is found
IF character equals a then mark as TRUE (found)
ELSE IF a is not found keep executing this code
Then search e: Start IF e is found
IF character equals e then mark as TRUE (found)
ELSE IF a is not found keep executing this code
Continue through each vowel remaining vowel (i,o,u)
CHECK if word has all five TRUE(found)
IF so, PRINT word
ELSE, move to next word and check flags.
Was This Post Helpful? 0
  • +
  • -

#10 BigAnt  Icon User is offline

  • May Your Swords Stay Sharp
  • member icon

Reputation: 101
  • View blog
  • Posts: 2,392
  • Joined: 16-August 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 06:12 PM

The for and if are indented to show the nesting. also for ...i,o,u you would repeat the two if's for each of these
READ the file to get the words
STORE each word in a String of words
For loop to read each word in the array of words
--Split the String into a character array
--FOR loop to read through the character array
----Check the occurrence of each vowel
------Start IF a is not yet found
--------IF character equals a then mark as TRUE (found)
--------ELSE IF a is not found move on to next character
------ELSE IF 'e' is not yet found
--------IF character equals e then mark as TRUE (found)
--------ELSE IF e is not found move on to next character
...i
...o
...u
--CHECK if word has all five TRUE(found)
--IF so, PRINT word
--ELSE, move to next word
Was This Post Helpful? 0
  • +
  • -

#11 Vychu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 28-October 08

Re: Writing a code to find words with all five consecutive vowels

Posted 28 October 2008 - 06:43 PM

Thanks so much BigAnt I really appreciate your help!
Was This Post Helpful? 0
  • +
  • -

#12 krazyrohil  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 14-August 09

Re: Writing a code to find words with all five consecutive vowels

Posted 14 August 2009 - 09:41 AM

[quote name='BigAnt' date='28 Oct, 2008 - 05:12 PM' post='448790']
can you please tell me how to check vowels without putting them in an array , using a user-defined function (such as isVowel)...???
i mean just by writing a single line code....
Was This Post Helpful? 0
  • +
  • -

#13 NeoTifa  Icon User is online

  • Whorediot
  • member icon





Reputation: 2731
  • View blog
  • Posts: 15,808
  • Joined: 24-September 08

Re: Writing a code to find words with all five consecutive vowels

Posted 14 August 2009 - 09:48 AM

Please don't necro threads. You can do a switch stame.

switch(word.equalsIgnoreCase) {

a:...
e:...
i:...
o:...
u:...

}
Was This Post Helpful? 0
  • +
  • -

#14 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10658
  • View blog
  • Posts: 39,569
  • Joined: 27-December 08

Re: Writing a code to find words with all five consecutive vowels

Posted 14 August 2009 - 12:24 PM

Let's use an int counter field instead of a million booleans. Let me demonstrate:

String x = "abcde";
for(int a = 0, y = 0; a < x.length; a++){
  if(y == 0 && 
	 (x.charAt(a) == 'a' || x.charAt(a) == 'A')) y++;
  if(y == 1 && 
	 (x.charAt(a) == 'e' || x.charAt(a) == 'E')) y++;
  //do the same thing for y == 2, 3, 4 w/i, o & u respectively
}



Remember, a String is a class with an array in the background. Hope this helps!
Was This Post Helpful? 0
  • +
  • -

#15 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10658
  • View blog
  • Posts: 39,569
  • Joined: 27-December 08

Re: Writing a code to find words with all five consecutive vowels

Posted 15 August 2009 - 12:31 PM

Sorry, but you'll need to use multiple lines of code to solve this problem. I applaud your desire for efficiency though.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2