Package stdlib
Class StdOut
java.lang.Object
stdlib.StdOut
This class provides methods for printing strings and numbers to standard output.
Differences with System.out.
The behavior of StdOut
is similar to that of System.out
,
ut there are a few technical differences:
-
StdOut
coerces the character-set encoding to UTF-8, which is a standard character encoding for Unicode. -
StdOut
coerces the locale toLocale.US
, for consistency withStdIn
,Double.parseDouble(String)
, and floating-point literals. -
StdOut
flushes standard output after each call toprint()
so that text will appear immediately in the terminal.
Reference. For additional documentation, see Section 1.5 of Computer Science: An Interdisciplinary Approach by Robert Sedgewick and Kevin Wayne.
- Author:
- Robert Sedgewick, Kevin Wayne
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Unit tests some of the methods inStdOut
.static void
print()
Flushes standard output.static void
print
(boolean x) Prints a boolean to standard output and flushes standard output.static void
print
(byte x) Prints a byte to standard output and flushes standard output.static void
print
(char x) Prints a character to standard output and flushes standard output.static void
print
(double x) Prints a double to standard output and flushes standard output.static void
print
(float x) Prints a float to standard output and flushes standard output.static void
print
(int x) Prints an integer to standard output and flushes standard output.static void
print
(long x) Prints a long integer to standard output and flushes standard output.static void
print
(short x) Prints a short integer to standard output and flushes standard output.static void
Prints an object to standard output and flushes standard output.static void
Prints a formatted string to standard output, using the specified format string and arguments, and then flushes standard output.static void
Prints a formatted string to standard output, using the locale and the specified format string and arguments; then flushes standard output.static void
println()
Terminates the current line by printing the line-separator string.static void
println
(boolean x) Prints a boolean to standard output and then terminates the line.static void
println
(byte x) Prints a byte to standard output and then terminates the line.static void
println
(char x) Prints a character to standard output and then terminates the line.static void
println
(double x) Prints a double to standard output and then terminates the line.static void
println
(float x) Prints an integer to standard output and then terminates the line.static void
println
(int x) Prints an integer to standard output and then terminates the line.static void
println
(long x) Prints a long to standard output and then terminates the line.static void
println
(short x) Prints a short integer to standard output and then terminates the line.static void
Prints an object to this output stream and then terminates the line.static void
resync()
If StdOut changes, use this to reinitialize the PrintWriter.
-
Method Details
-
println
public static void println()Terminates the current line by printing the line-separator string. -
println
Prints an object to this output stream and then terminates the line.- Parameters:
x
- the object to print
-
println
public static void println(boolean x) Prints a boolean to standard output and then terminates the line.- Parameters:
x
- the boolean to print
-
println
public static void println(char x) Prints a character to standard output and then terminates the line.- Parameters:
x
- the character to print
-
println
public static void println(double x) Prints a double to standard output and then terminates the line.- Parameters:
x
- the double to print
-
println
public static void println(float x) Prints an integer to standard output and then terminates the line.- Parameters:
x
- the integer to print
-
println
public static void println(int x) Prints an integer to standard output and then terminates the line.- Parameters:
x
- the integer to print
-
println
public static void println(long x) Prints a long to standard output and then terminates the line.- Parameters:
x
- the long to print
-
println
public static void println(short x) Prints a short integer to standard output and then terminates the line.- Parameters:
x
- the short to print
-
println
public static void println(byte x) Prints a byte to standard output and then terminates the line.To write binary data, see
BinaryStdOut
.- Parameters:
x
- the byte to print
-
print
public static void print()Flushes standard output. -
print
Prints an object to standard output and flushes standard output.- Parameters:
x
- the object to print
-
print
public static void print(boolean x) Prints a boolean to standard output and flushes standard output.- Parameters:
x
- the boolean to print
-
print
public static void print(char x) Prints a character to standard output and flushes standard output.- Parameters:
x
- the character to print
-
print
public static void print(double x) Prints a double to standard output and flushes standard output.- Parameters:
x
- the double to print
-
print
public static void print(float x) Prints a float to standard output and flushes standard output.- Parameters:
x
- the float to print
-
print
public static void print(int x) Prints an integer to standard output and flushes standard output.- Parameters:
x
- the integer to print
-
print
public static void print(long x) Prints a long integer to standard output and flushes standard output.- Parameters:
x
- the long integer to print
-
print
public static void print(short x) Prints a short integer to standard output and flushes standard output.- Parameters:
x
- the short integer to print
-
print
public static void print(byte x) Prints a byte to standard output and flushes standard output.- Parameters:
x
- the byte to print
-
printf
Prints a formatted string to standard output, using the specified format string and arguments, and then flushes standard output.- Parameters:
format
- the format stringargs
- the arguments accompanying the format string
-
printf
Prints a formatted string to standard output, using the locale and the specified format string and arguments; then flushes standard output.- Parameters:
locale
- the localeformat
- the the format stringargs
- the arguments accompanying the format string
-
resync
public static void resync()If StdOut changes, use this to reinitialize the PrintWriter. -
main
Unit tests some of the methods inStdOut
.- Parameters:
args
- the command-line arguments
-