|
-
June 23rd, 2015, 03:51 PM
#1
How to turn String into Pig Latin
Im trying to turn a string taken from the user into piglatin. I cannot use any special classes, methods, or arrays. I can only use a Scanner to create a object to take the string from the user and .length and .charAt, in addition to any type of looping. (Also cannot use switch statements or the break keyword)
Here is an example of what my output is suppose to be:
Enter a line of text: this is a test.
Input : this is a test.
Output: his-tay is-way a-way est-tay
Here is my code, I can only get my code to work with one word and it must have a space at the end. Only one loop works at a time depending on the loop. Im not sure what to do if I get an entire String. Would you please mind showing me what I'm doing wrong? Thank you.
Code:
import java.util.*;
public class pL {
public static void main(String[] args) {
boolean space = false;
char firstChar;
System.out.print("Enter a line of text: ");
Scanner keyboard = new Scanner(System.in);
String text = keyboard.nextLine();
System.out.println("\nInput: " + text);
System.out.print("Output: ");
/*for (int i = 0; i < text.length(); i++) {
if (((text.charAt(i)) == ('a')) || ((text.charAt(i)) == ('e'))
|| ((text.charAt(i)) == ('i'))
|| ((text.charAt(i)) == ('o'))
|| ((text.charAt(i)) == ('u'))) {
System.out.print(text.charAt(i));
} else if (text.charAt(i) == ' ') {
System.out.print("-way ");
} else
System.out.print(text.charAt(i));
}
*/
/*for (int i = 0; i < text.length(); i++) {
firstChar = text.charAt(0);
if (text.charAt(i) == ' ')
System.out.print("-" + firstChar + "ay ");
else if (text.charAt(i) != text.charAt(0)) {
System.out.print(text.charAt(i));
}
}
*/
}
}
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|