Methods Summary |
---|
public static char | getKey(java.lang.String prompt)read a string from the console. The string is
terminated by a newline
printPrompt(prompt);
int ch = '\n";
try
{
ch = System.in.read();
}
catch(java.io.IOException e)
{
}
return (char)ch;
|
public static void | printPrompt(java.lang.String prompt)print a prompt on the console but don't print a newline
System.out.print(prompt + " ");
System.out.flush();
|
public static double | readDouble(java.lang.String prompt)read a floating point number from the console.
The input is terminated by a newline
while(true)
{
printPrompt(prompt);
try
{
return Double.parseDouble(readLine().trim());
}
catch(NumberFormatException e)
{
System.out.println("Not a floating point number. Please try again!");
}
}
|
public static int | readInt(java.lang.String prompt)read an integer from the console. The input is
terminated by a newline
while(true)
{
printPrompt(prompt);
try
{
return Integer.valueOf
(readLine().trim()).intValue();
}
catch(NumberFormatException e)
{
System.out.println("Not an integer. Please try again!");
}
}
|
public static java.lang.String | readLine()read a string from the console. The string is
terminated by a newline
int ch;
String r = "";
boolean done = false;
while (!done)
{
try
{
ch = System.in.read();
if (ch < 0 || (char)ch == '\n")
done = true;
else if ((char)ch != '\r") // weird--it used to do \r\n translation
r = r + (char) ch;
}
catch(java.io.IOException e)
{
done = true;
}
}
return r;
|
public static java.lang.String | readLine(java.lang.String prompt)read a string from the console. The string is
terminated by a newline
printPrompt(prompt);
return readLine();
|