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
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
1.) Open command prompt
- go to run
- type cmd
- press enter
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
Post a Comment