A Java Program that exits when you double press enter

Many people have problem thinking how they can exit their java program by double pressing enter key and they often use complicated methods like Scanner class and StringBuffer. Here is the simplest way to do this without using any complicated commands
1.) Open command prompt

  •   go to run
  •   type cmd
  •   press enter
2.) type edit enter_exit.java (here enter_exit is the name of the class file of your program and .java is the extension)
3.) copy this code
 
import java.io.*;
class enter_exit
{
 public static void main(String ar[])throws IOException
 {
  BufferedReader z=new BufferedReader(new InputStreamReader(System.in));
  String s;
  while(true)
  {
   System.out.println("Enter your input");
   s=z.readLine();
   if(s.length()==0)
   {
    System.out.println("Enter your input");
    s=z.readLine();
    if(s.length()==0)
    break;
   }
  }
 }
}


That's it now compile using javac enter_exit.java and then run using java enter_exit

Comments

Popular posts from this blog

Matrix Falling Code Effect

The Windows 10 Fall Creator's Update: What's new?

Why should you Disable 2.4 GHz Wi-Fi on your Network and How