Java fprintf, printf, sprintf (fscanf, scanf, sscanf)





Java scanf


In addition to the format specification description below there are also

Format specification

This is the format of one conversion specification.

.    __%__ _________ __ _________ __ ________________ __type__
 .         |         |  |         |  |                |
 .         |__flags__|  |__width__|  |__.__precision__|


% flag* [width] [.precision] type

Field description

flags Justification of output and printing of signs, blanks, decimal points, octal, and hexadecimal prefixes, and the semantics for wchar_t precision unit.

width Minimum number of characters (bytes) output.

precision Maximum number of characters (bytes) printed for all or part of the output field, or minimum number of digits printed for integer values.

Flag Brief description
- (minus sign) Left adjusted, otherwise right adjusted.
+ (plus sign) Prefix the output value with a sign (+ or -) if the output value is of a signed type. Default is that sign appears only for negative values (-). 
' ' (blank) A nonnegative value will have a space prepended. The + flag overrides the blank flag if both appear, and a positive value will be output with a sign. 
# (pound) Alternative form. When used with the o, x, X, b or B formats, the # flag prefixes any output value with 0, 0x, 0X, 0b or 0B, respectively. When used with the f, e, or E formats, the # flag forces the output value to contain a decimal point in all cases. When used with the c format, the # flag forces the output value to be in UTF-encoding, e.g. A. 
0 (zero) When used with the b, B, d, i, u, o, x, X, e, E, f, g, or G formats, the 0 flag causes leading 0's to pad the output to the field width. The 0 flag is ignored if the - flag is specified. 
Width Brief description
* (asterix) The value for the precision will be obtained from the parameter list. If the value is negative the output will be left-justified.
n (an integer) A nonnegative integer for the width; e.g. 8.
Precision Brief description
* (asterix) The value for the width will be obtained from the parameter list.
n (an integer) A nonnegative integer for the precision; e.g. 3.
Corresponding argument 
will be printed as
l,L1 a logical value, i.e. a boolean values; e.g. true, FALSE. Also support for C-style booleans, i.e. 0 or 1 (<>0). 
c a character.
d, i a decimal integer.
u an unsigned integer. This flag is applicable to the byte, the short and the int data types only.
b1 a binary integer.
x,X a hexadecimal integer.
o an octal integer.
e,E a scientific floating point number; e.g. 1.23E-03.
f a floating point number; e.g. 0.00123.
g,G %e or %E is used if the exponent is less than -4 or greater than or equal to the precision; otherwise %f is used. Trailing zeros are truncated, and the decimal point appears only if one or more digits follow it.
s a string. All characters in String is printed or as many as precision specifies.
% There is no corresponding argument, i.e. To output "%" one have to put "%%" in the format string.

Not an ANSI-C standard.