Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to do a system pause in java for debugging?

Tags:

java

Is there any functionality in Java for pausing the program like system("PAUSE"); does in C++?

like image 575
kokokok Avatar asked Nov 28 '22 12:11

kokokok


1 Answers

The Short Is Yes, But You Have To Build It Using The Standard Output With System.out and Using The Scanner Class To Wait For New Line Input ('\n') From Standard Input From The System.in

public class PauseTest {

     public static void main(String args[]){

          System.out.println("Press Any Key To Continue...");
          new java.util.Scanner(System.in).nextLine();
     }
}

NOTE: I used a direct reference to the Scanner Class in java.util package, but you could simply add the import java.util.Scanner; or import java.util.*; Basically the same thing.

like image 167
Wemilianius Avatar answered Dec 05 '22 10:12

Wemilianius