I am trying to make a program that would translate english into pig latin. I have written my code however i keep getting the error "Syntax error on token "void", record expectedJava(1610612940)".
import java.util.Scanner;
public static void main(String[] args) {
public String pigLatin(String word){
Scanner input = new Scanner(System.in);
String userin = input.nextLine();
int InLength = userin.length();
String firstletter = userin.substring(0, 1);
if(firstletter.matches(".*[bdgnrs].*"))
{
System.out.println("yes");
}
input.close();
return firstletter;
}
}
Thank you.
CodePudding user response:
First, you need a class to put in you main() method
import java.util.Scanner;
public class Mytest {
public static void main(String[] args) {
pigLatin("baby");
}
public static String pigLatin(String word){
Scanner input = new Scanner(System.in);
String userin = input.nextLine();
int InLength = userin.length();
String firstletter = userin.substring(0, 1);
if(firstletter.matches(".*[bdgnrs].*")){
System.out.println("yes");
}
input.close();
return firstletter;
}
}
With this your code is calling your pigLatin method, but I don't know if code inside is working as you expect
Regards,