Ignoring all the other advice going around, perhaps an explanation is in order:
What you wrote is a console program. If you do not have the console open in advance (say, but using Start: Run: cmd), what happens is launching the program also launches the console window. It then produces its output and closes. By default, console windows close when the program they were created for closes.
The best practice, for my money, is to have your IDE open, and a console window as well. You code/compile in the IDE, but run from the console.