Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Syntax error on token "void", record expectedJava(1610612940)

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) {

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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,

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading