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);
}
}
}
Thank you angryboy for the idea and thank you RamyaSivakanth for the hint
I tried all the possibilities using trim(), equals(), == and != but the program exit befor i can type anything do you have any idea?
Hi,
Just compare your code with my code and u can find the differnce where u are going wrong.If u ahve any problems ,I will explain you.
import java.util.Scanner;
import java.io.*;
Code:
public class Test
{
public static void main(String[] args) throws Exception
{
// TODO, add your application code
System.out.println("Enter any character or Enter 'exit' to exit");
BufferedReader DataIn = new BufferedReader(new InputStreamReader(System.in));
String StringX = "";
System.out.println("you can type anything here, just dont leave it empty");
while ( !StringX.trim().equalsIgnoreCase("exit"))
{
StringX = DataIn.readLine();
char charX[] = StringX.toCharArray();
System.out.println("The First Character you have entered is: " +charX[0]);
}//while
}//main
} //class