Four ways:
Method 1: When running a program, instead of executing it with the F5 key, use Ctrl+F5 to execute it, which means “Start Execution (Not Debugging)”, so it won’t flash by.
Method 2: Add this console.readline () at the end of your code; That is, “wait for user input,” so the DOS window won’t close until you hit enter
Method 3: Add console.readKey () at the end of the program; The DOS window will not exit until it receives a character.
Method 4: Run the program under CMD.