I'm currently working on a program which is pig Latin. It allows a user enter a sentence. The program would take the user input and change every word in to pig latin which it takes the first character of a word and add it to end of word with "ay". For instance, bog would be "ogday" This is what I have been done so far
import java.util.Scanner;
public class PigLatinTest
{
public static void main(String[] args)
{
Scanner kybd = new Scanner(System.in);
System.out.println("Please enter a sentence?");
String enSentence = kybd.nextLine();
//StringBuilder buffer = new StringBuilder(enSentence);
}
public static String convertToLatin(String s)
{
StringBuilder buffer = new StringBuilder();
String [] sentence = s.split("");
String k ="ay";
for (String i:sentence)
{
buffer.insert(buffer.lastIndexOf(i), buffer.charAt(0));
buffer.insert(buffer.lastIndexOf(i), k);
buffer.delete(0,2);
}
}
}
I wonder whether I did my convertToLatin correct or not? My other question is after the for loop loop each word, will the data in sentence array change? Or do I need to store the change into other array in order to access the change data?
Thank you so much.