The Artima Developer Community
Sponsored Link

Java Answers Forum
vowel array compare with name entered

5 replies on 1 page. Most recent reply: May 2, 2004 8:18 PM by Kishori Sharan

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
Donna

Posts: 1
Nickname: djean
Registered: Apr, 2004

vowel array compare with name entered Posted: Apr 25, 2004 12:38 PM
Reply to this message Reply
Advertisement
assignment Name Game - due tomorrow! Please help!
Desperately seeking a solution! I have to determine where the vowel is in the name entered and save the remainder of the name (including the vowel) to be output in the "Name Game" parody. for instance if you enter Sam:
Sam, Sam, Bo Bam
Banana Fana Fo Fam
Me Mi Mo Mam
Sam
My code is as follows:
public static String lookFor(String strIn) {

boolean found=false;
String suffix = new String();
int index = 0;
int i, len;
int j=0;
String vowelsArray[] = {"a", "e", "i", "o", "u", "y"};

len = strIn.length();
for (i=0; i<len; i++){
strIn.substring(i).equalsIgnoreCase (vowelsArray[j+1]);
suffix = strIn.substring(i);
}

return suffix;

} //end method lookFor
What am I doing wrong?


Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: vowel array compare with name entered Posted: Apr 25, 2004 2:40 PM
Reply to this message Reply
The following code may help you to complete your program.
public class Test {
	public final static char VOWELS[] = {'a', 'e', 'i', 'o', 'u', 'y'};
 
	public static void main(String[] args) throws Exception {
		String str = "Mama";
 
		if ( args.length > 0 ) {
			str = args[0];
		}
 
		System.out.println ( lookFor ( str )  ) ;
	}
 
	// Throws exception when no vowel is found in the string
	public static String lookFor(String input) throws Exception {
 
		if ( input == null || input.trim().equals("") ) {
			throw new Exception ("No vowel found");
		}
 
		int len = input.length();
 
		char c = 0;
		boolean found = false;
 
		int i = 0 ;
		outer:
		for ( ; i < len; i++) {
			// Get the character from string
			c = input.charAt(i) ;
			for ( int j = 0 ; j < VOWELS.length; j++ ) {
				if ( c == VOWELS[j] ) {
					found = true;
					break outer;
				}
			}
 
		}
 
 
		String suffix = null;
 
		if ( found ) {
			suffix = input.substring(i);
		}
		else {
			throw new Exception ("No vowel found");
		}
 
		return suffix;
	}
}

Sanjay Perera

Posts: 42
Nickname: angel6
Registered: Apr, 2004

Re: vowel array compare with name entered Posted: Apr 30, 2004 6:40 AM
Reply to this message Reply
GUYS, WHEN DID ANYONE HEAR ABOUT A VOWEL "Y"????

Adam Duffy

Posts: 168
Nickname: adamduffy
Registered: Feb, 2003

Re: vowel array compare with name entered Posted: Apr 30, 2004 8:04 AM
Reply to this message Reply
I've often thought that "y" should be a vowel. Just to balance things out a bit since there are so many other consonants.

Adam

Thomas W. Cowdery

Posts: 1
Nickname: twcowdery
Registered: Feb, 2004

Re: vowel array compare with name entered Posted: Apr 30, 2004 11:26 AM
Reply to this message Reply
> GUYS, WHEN DID ANYONE HEAR ABOUT A VOWEL "Y"????

In English, Y is considered either a vowel or a consonant, depending on useage.

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: vowel array compare with name entered Posted: May 2, 2004 8:18 PM
Reply to this message Reply
Mr. Perera
L, J, W (and many more alphabets) are also considered vowels.

Flat View: This topic has 5 replies on 1 page
Topic: I need help with this java application Previous Topic   Next Topic Topic: Whats wrong?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use