Code:
public static char readLineNonwhiteChar()
{
boolean done = false;
String inputString = null;
char nonWhite = ' ';//To keep the compiler happy.
while (! done)
{
inputString = readLine();
inputString = inputString.trim();
if (inputString.length() == 0)
{
System.out.println(
"Your input is not correct.");
System.out.println("Your input must contain at");
System.out.println(
"least one nonwhitespace character.");
System.out.println("Please, try again.");
System.out.println("Enter input:");
}
else
{
nonWhite = (inputString.charAt(0));
done = true;
}
}
return nonWhite;
}
Das hier benutzen wir auf der Uni, hoffe das hilft dir.