Results 1 to 3 of 3
Thread: Multiple if statements
- 09-28-2011, 10:25 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
Multiple if statements
I am a new Java user. I have just about 1 or 2 weeks of experience, but I really enjoy tweaking with Java programming with the little knowledge I have.
I decided to make a name Pig Latinizer, but despite my efforts I haven't met certain goals I am trying to achieve.
Now I understand that their are probably many loopholes for invalid input (Like a name that contains a invalid characters sandwiched between vowels and consonants) but I do want to make it as sturdy as possible without going to complex (like some of the pig latin programs Ive googled to try and find these answers)
My issue are
1) attempting to eliminate multiple if statements
2) continuing the program after I Print "invalid"
3) and adding a more thorough check for invalid character
4) Suggestions on how to use this process for multiple words
The code is as follows (shortened):
final String vowel = "aeiou";
final String consenant = "bcdfghjklmnpqrstvwxyz";
System.out.println("Enter your name: ");
yourname = keyboard.nextLine();
int length = yourname.length();
char begin = yourname.charAt(0);
char begin2 = yourname.charAt(1);
if(consenant.indexOf(yourname) == -1 || vowel.indexOf(yourname) == -1)
{
System.out.println("Invalid! Please enter a valid name:");
yourname = keyboard.nextLine();
}
if (consenant.indexOf(begin) != -1 && consenant.indexOf(begin2) == -1)
{
pigname = yourname.substring(1,length);
System.out.println(pigname+begin+"ay");
}
if (consenant.indexOf(begin) != -1 && consenant.indexOf(begin2) != -1)
{
pigname = yourname.substring(2,length);
System.out.println(pigname+begin+begin2+"ay");
}
if (vowel.indexOf(begin) != -1)
{
pigname = yourname+"way";
System.out.println(pigname);
I am making this for learning purposes so please try and not give my answers that are too complex, if they cannot be explained for me to understand
Much appreciation,
GunnerLast edited by gunnerp420; 09-28-2011 at 10:56 PM. Reason: Forgot code lol
- 09-28-2011, 10:45 PM #2
Senior Member
- Join Date
- Nov 2010
- Posts
- 210
- Rep Power
- 3
Re: Multiple if statements
Won't consenant.indexOf(yourname) only return a positive value if yourname consists entirely of consecutive consonants?
- 09-28-2011, 10:54 PM #3
Member
- Join Date
- Sep 2011
- Posts
- 2
- Rep Power
- 0
Similar Threads
-
how to call multiple sql statements in java
By sandeep43 in forum JDBCReplies: 5Last Post: 08-01-2011, 10:13 AM -
multiple Data from Jsp that having same name of multiple input tage to servlet
By rahul9323.2007@gmail.com in forum Advanced JavaReplies: 0Last Post: 07-29-2011, 01:00 PM -
if statements for multiple variables
By dookie1293 in forum New To JavaReplies: 9Last Post: 06-17-2011, 09:30 AM -
Effect of Multiple Condtitions in if() statements to run time
By kimhonoridez in forum New To JavaReplies: 4Last Post: 12-08-2010, 08:40 AM -
Running multiple threads on multiple CPU cores?
By Dosta in forum Threads and SynchronizationReplies: 2Last Post: 09-19-2010, 03:48 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks