My assignment is to use a method to do the pig latin part of a program I have already done. So basically, I have the program written, code is below, but am getting two errors in it. I have not really gone over using strings and returning them to the main program in my class yet, but after viewing some other questions on this site, I found some hints to what I needed to do for it. I thought I had done it right, but does not compile. This program has two errors.
Error #1 is with the output statement when I try to use the string variable 'word' at the end of the output statement. I am trying to use the string that is in the variable after the function runs. The error tells me that there is a syntax error on token "word" and I should delete this token.
Error #2 is with the actual function title. The compiler says there are errors on each end of the parameter, underlining both '(' and ')' in red, but not what is contained in the middle of them. The compiler tells me that there is a syntax error and that a semicolon is expected there.
Here is the code. Thanks in advance for any assistance in this matter. I have only been doing Java for about two months now.
import java.util.*;
public class PigLatinWithFunctions {
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String x, y, z;
System.out.println("Enter a word :");
x = keyboard.nextLine();
PigLatin(x);
System.out.println("The word you entered in pig latin is " + word);
}
public static String PigLatin(String x)
{
String word;
y = x.substring(1);
z = x.substring(0, 1);
word = y + z + "ay";
return word;
}
}
}