Class StdIn
java.lang.Object
uk.ac.gda.excalibur.config.model.fit.StdIn
Standard input. This class provides methods for reading strings
and numbers from standard input.
The Locale used is: language = English, country = US. This is consistent with the formatting conventions with Java floating-point literals, command-line arguments (via Double.parseDouble()) and standard output (via System.out.print()). It ensures that standard input works with the input files used in the textbook.
For additional documentation, see Section 1.5 of Introduction to Programming in Java: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanDoes standard input have a next line?static booleanisEmpty()Is there only whitespace left on standard input?static voidUnit teststatic StringreadAll()Return rest of input from standard inputstatic booleanReturn next boolean from standard input, allowing "true" or "1" for true, and "false" or "0" for falsestatic bytereadByte()Return next byte from standard inputstatic charreadChar()Return next char from standard inputstatic doubleReturn next double from standard inputstatic double[]Read rest of input as array of doublesstatic floatReturn next float from standard inputstatic intreadInt()Return next int from standard inputstatic int[]readInts()Read rest of input as array of intsstatic StringreadLine()Return rest of line from standard inputstatic longreadLong()Return next long from standard inputstatic shortReturn next short from standard inputstatic StringReturn next string from standard inputstatic String[]Read rest of input as array of strings
-
Method Details
-
isEmpty
public static boolean isEmpty()Is there only whitespace left on standard input? -
readString
Return next string from standard input -
readInt
public static int readInt()Return next int from standard input -
readDouble
public static double readDouble()Return next double from standard input -
readFloat
public static float readFloat()Return next float from standard input -
readShort
public static short readShort()Return next short from standard input -
readLong
public static long readLong()Return next long from standard input -
readByte
public static byte readByte()Return next byte from standard input -
readBoolean
public static boolean readBoolean()Return next boolean from standard input, allowing "true" or "1" for true, and "false" or "0" for false -
hasNextLine
public static boolean hasNextLine()Does standard input have a next line? -
readLine
Return rest of line from standard input -
readChar
public static char readChar()Return next char from standard input -
readAll
Return rest of input from standard input -
readInts
public static int[] readInts()Read rest of input as array of ints -
readDoubles
public static double[] readDoubles()Read rest of input as array of doubles -
readStrings
Read rest of input as array of strings -
main
Unit test
-