Reputation: 11
please tell what format specifier is used for "short" data type in java? Like %d is used for integer %s is used for string.
Upvotes: 0
Views: 1311
Reputation: 1473
From primitive data types:
short
: Theshort
data type is a 16-bit signed two's complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive). As withbyte
, the same guidelines apply: you can use ashort
to save memory in large arrays, in situations where the memory savings actually matters.
A short is an integer, so using %d
is the correct way.
Upvotes: 1
Reputation: 6809
There is none. short
is just a 16-bit integer, so use %d
.
If you want an unsigned short
, use this code.
short s;
int unsignedShort = ((int) s) & 0xFFFF;
and use that value with %d
.
Upvotes: 1