public class FormatWriter
extends java.lang.Object
FormatWriter
class has a collection of static methods for
writing formatted output to System.out.
Java Source Code for this class:
http://www.cs.colorado.edu/~main/edu/colorado/io/FormatWriter.java
EasyReader
Constructor and Description |
---|
FormatWriter() |
Modifier and Type | Method and Description |
---|---|
static void |
main(java.lang.String[] args)
A demonstration program.
|
static void |
pause(long milliseconds)
Make the computation pause for a specified number of milliseconds.
|
static void |
printLeft(java.lang.Object output,
int minimumWidth)
Print an
Object (such as a String ) to
System.out , using left justification. |
static void |
printNumber(double d,
int minimumWidth,
int fractionDigits)
Print a number to
System.out , using a specified format. |
static void |
printRight(java.lang.Object output,
int minimumWidth)
Print an
Object (such as a String ) to
System.out , using right justification. |
static void |
printWhole(long n,
int minimumWidth)
Print a whole number to
System.out , using a specified format. |
public static void pause(long milliseconds)
milliseconds
- the number of milliseconds to pause
Postcondition:
The computation has paused for the specified time.public static void printNumber(double d, int minimumWidth, int fractionDigits)
System.out
, using a specified format.d
- the number to be printedminimumWidth
- the minimum number of characters in the entire outputfractionDigits
- the number of digits to print on the right side of the decimal point
Precondition:
fractionDigits
is not negative.
Postcondition:
The number d
has been printed to System.out
.
This printed number is rounded to the specified number of digits on the
right of the decimal. If fractionDigits
is 0, then only the
integer part of d
is printed. If necessary, spaces appear
at the front of the number to raise the total number of printed
characters to the minimum. Additional formatting details are obtained
from the current locale. For example, in the United States, a period is
used for the decimal and commas are used to separate groups of
integer digits.java.lang.IllegalArgumentException
- Indicates that fractionDigits
is negative.
Example:
printNumber(12345.27, 8, 1);
public static void printLeft(java.lang.Object output, int minimumWidth)
Object
(such as a String
) to
System.out
, using left justification.output
- the Object to be printedminimumWidth
- the minimum number of characters in the entire output
Postcondition:
The Object
has been printed to System.out
.
If necessary, spaces appear
at the front of the Object to raise the total number of printed
characters to the minimum.
Example:
printNumber("Foo", 8);
public static void printRight(java.lang.Object output, int minimumWidth)
Object
(such as a String
) to
System.out
, using right justification.output
- the Object to be printedminimumWidth
- the minimum number of characters in the entire output
Postcondition:
The Object
has been printed to System.out
.
If necessary, spaces appear
at the front of the Object to raise the total number of printed
characters to the minimum.
Example:
printNumber("Foo", 8);
public static void printWhole(long n, int minimumWidth)
System.out
, using a specified format.n
- the number to be printedminimumWidth
- the minimum number of characters in the entire output
Postcondition:
The number n
has been printed to System.out
.
If necessary, spaces appear
at the front of the number to raise the total number of printed
characters to the minimum. Additional formatting details are obtained
from the current locale. For example, in the United States
commas are used to separate groups of
integer digits.
Example:
printNumber(12345, 8);
public static void main(java.lang.String[] args)
java edu.colorado.io.FormatWriter
args
- not used in this implementation