Java Reference
In-Depth Information
int
int
[]
numbers
= {
0
,
3
,
8
};
// Presumably this would be somewhere else in the code.
for
for
(
int
int
n
:
numbers
) {
System
.
out
.
println
(
"Month: "
+
months
[
n
]);
}
}
/** The names of the months. See Dates/Times chapter for a better way */
protected
protected static
static
String months
[] = {
"January"
,
"February"
,
"March"
,
"April"
,
"May"
,
"June"
,
"July"
,
"August"
,
"September"
,
"October"
,
"November"
,
"December"
};
}
Working with Roman Numerals
Problem
You need to format numbers as Roman numerals. Perhaps you've just written the next
Titan-
ic
or
Star Wars
episode and you need to get the copyright date correct on the script. Or, on a
more mundane level, you need to format page numbers in the front matter of a book.
Solution
Use my
RomanNumberFormat
class:
RomanNumberFormat nf
=
new
new
RomanNumberFormat
();
int
int
year
=
LocalDate
.
now
().
getYear
();
System
.
out
.
println
(
year
+
" -> "
+
nf
.
format
(
year
));
Running
RomanNumberSimple
produces this output:
2014 -> MMXIV