Class StdIn

Object
  extended by StdIn

public final class StdIn
extends Object

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
static boolean hasNextLine()
          Does standard input have a next line?
static boolean isEmpty()
          Is there only whitespace left on standard input?
static void main(String[] args)
          Unit test
static String readAll()
          Return rest of input from standard input
static boolean readBoolean()
          Return next boolean from standard input, allowing "true" or "1" for true, and "false" or "0" for false
static byte readByte()
          Return next byte from standard input
static char readChar()
          Return next char from standard input
static double readDouble()
          Return next double from standard input
static double[] readDoubles()
          Read rest of input as array of doubles
static float readFloat()
          Return next float from standard input
static int readInt()
          Return next int from standard input
static int[] readInts()
          Read rest of input as array of ints
static String readLine()
          Return rest of line from standard input
static long readLong()
          Return next long from standard input
static short readShort()
          Return next short from standard input
static String readString()
          Return next string from standard input
static String[] readStrings()
          Read rest of input as array of strings
 
Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isEmpty

public static boolean isEmpty()
Is there only whitespace left on standard input?


readString

public static String 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

public static String readLine()
Return rest of line from standard input


readChar

public static char readChar()
Return next char from standard input


readAll

public static String 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

public static String[] readStrings()
Read rest of input as array of strings


main

public static void main(String[] args)
Unit test