Hi so im trying to do this pig latin code in which the first letter is deleted from a words and sent to the end of the word while adding an "ay" to the end result. I have finished all my code in which it should output the right result except my problem is with actually outputting the code. I get an error message right after the user inputs the sentence.
Here is my code:
package piglatin;
import java.util.Scanner;
public class PigLatinTest {
public static String str;
public static String[] words;
public static String[] printLatinWords()
{
System.out.println("Enter a Sentence: ");
Scanner scanner = new Scanner(System.in);
str = scanner.nextLine();
words = str.split(" ");
//System.out.println(words);
return words;
}
public static String[] printPigLatinWords()
{
for (int i = 0; i < words.length; i++) {
char firstLetter = words[i].charAt(0);
words[i] = words[i].substring(1);
words[i] = words[i] + firstLetter + "ay";
//System.out.println(words[i]);
//If you want the words to be in the same line, then this could help instead of System.out.println:
System.out.print(words[i] + " ");
}
return words;
}
public static void main(String[] args)
{
words = printLatinWords();
}
}
/*
Enter a Sentence:
Hello from the other side
*/