How to exit the program by typing "exit"?
How to exit the program by typing "exit"?
this is the code that i came up with:
Code:
import java.io.*;
public class GetCharacterMethodX
{
public static void main(String Laythe[])
{
System.out.println("Enter any character or Enter 'exit' to exit");
BufferedReader DataIn = new BufferedReader(new InputStreamReader(System.in));
String StringX = "";
while ( StringX != "you can type anything here, just dont leave it empty" )
{
if (StringX != "exit" )
{
try
{
StringX = DataIn.readLine();
}
catch (IOException E)
{
System.out.println("Error!");
}
char charX[] = StringX.toCharArray();
try
{
System.out.println("The First Character you have entered is: " +charX[0]);
}
catch (Exception E)
{
}
}
else
{
System.exit(0);
}
}
}