1

I am trying to get the user to enter their name and have it be printed out on java using Sublime Text 3. After the user enters their name when a message prompts them for it, their name is supposed to be printed out but it justs skips over to a new blank line. It works on online compilers but not on Sublime. How do I get user console input to work on Java Sublime Text 3?

import java.util.Scanner;

public class SocSecProcessor {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        System.out.print("Enter name: ");
        String name = input.nextLine();
        input.close();
        System.out.println(name);

    }

}

1 Answers1

0

You have to launch execution in a separate console, not the sublime text pseudo console. The solution is to launch with START command in a batch file .bat for example:

START CMD /K %RELATIVE_PATH%\jdk\bin\java -cp %~dp1 %~n1

where %1 is the file class with main method. Go to the batch syntax documentation if necessary... Your build system in sublime must launch a batch file with this kind of instruction.

Alan Allen
  • 71
  • 5