Results 1 to 3 of 3
  1. #1
    gunnerp420 is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Lightbulb 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,
    Gunner
    Last edited by gunnerp420; 09-28-2011 at 10:56 PM. Reason: Forgot code lol

  2. #2
    Iron Lion is offline Senior Member
    Join Date
    Nov 2010
    Posts
    210
    Rep Power
    4

    Default Re: Multiple if statements

    Won't consenant.indexOf(yourname) only return a positive value if yourname consists entirely of consecutive consonants?

  3. #3
    gunnerp420 is offline Member
    Join Date
    Sep 2011
    Posts
    2
    Rep Power
    0

    Default Re: Multiple if statements

    I thought the same thing
    But it seems to run fine O.o

Similar Threads

  1. how to call multiple sql statements in java
    By sandeep43 in forum JDBC
    Replies: 5
    Last Post: 08-01-2011, 10:13 AM
  2. multiple Data from Jsp that having same name of multiple input tage to servlet
    By rahul9323.2007@gmail.com in forum Advanced Java
    Replies: 0
    Last Post: 07-29-2011, 01:00 PM
  3. if statements for multiple variables
    By dookie1293 in forum New To Java
    Replies: 9
    Last Post: 06-17-2011, 09:30 AM
  4. Replies: 4
    Last Post: 12-08-2010, 08:40 AM
  5. Running multiple threads on multiple CPU cores?
    By Dosta in forum Threads and Synchronization
    Replies: 2
    Last Post: 09-19-2010, 03:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •