// Will take user string and print it out to show initial state
System.out.print("Input your sentence for conversion to Pig Latin: ");
startSentence = keyboard.nextLine(); // Add the name input into the name variable
System.out.println("Your sentence is - " + startSentence);

Then in the body of the code I checked for -1 and if that was the case, I just ran:

Code:

else if (value == -1)
{
breakSentence[ctr] = breakSentence[ctr];
}

Seems to work. I am sure my code can be more elegant. I planning on splitting it out into separate classes as well. Just haven't gotten there yet.

04-03-2013, 03:37 PM

KevinWorkman

Re: Numbers in Pig Latin Code

That's one way to do it, but you could have reduced that 10-element if statement down to a single boolean expression using the Pattern class. For that matter, you could have used the methods in the Character class as well. But as long as it works, go with it.