Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you keep the console from closing after the program is done?

How do you keep the console from closing after the program is done in Java?

like image 932
mikigal Avatar asked Oct 17 '25 14:10

mikigal


2 Answers

readLine() waits until you press a key:

public static void main (String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    in.readLine();
}
like image 85
Willi Mentzel Avatar answered Oct 20 '25 02:10

Willi Mentzel


The simplest way I've found:

Scanner scanner = new Scanner(System.in); 
scanner.nextLine();
like image 39
Ruben Avatar answered Oct 20 '25 02:10

Ruben