java - How do I get user input when I run my jar file from command prompt? -
in netbeans, program works perfectly. gets user input using scanner.
however, when run jar file in command prompt, skips user input , runs program anyways. why , how correct this?
example:
public static void main(string[] args) { system.out.print("how many teachers need assignment (two classes assigned each teacher)? "); numteachers = input.next(); }
it never prints out first line either
because first line never prints think find issue caused how run program, because if works in netbeans that's difference.
first open console window in folder program run jar file normal:
java -jar myapplication.jar
if double click jar file run instantly, , because there no console close instantly. java programs use console must run console/command prompt/terminal.
edit: in case, worth double checking how setup scanner. should example: https://stackoverflow.com/a/17691245/1270000
public static void main(string args[]){ scanner scanner = new scanner(system.in); int eid,sid; string ename; system.out.println("enter employeeid:"); eid=scanner.nextint(); scanner.nextline(); //this needed pick new line system.out.println("enter employeename:"); ename=scanner.nextline(); system.out.println("enter supervisiorid:"); sid=(scanner.nextint()); }