Say we have a number
int number = 1234
and I want to use formatting to extract the final two digits as a string 34
. How can one accomplish that?
I attempted:
String extraction = String.format("%d", number)
but this simply copies the entire number. I'm new to the syntax used by the formatter and can't seem to figure out the syntax that can go inside the characters of a number (or a String, for that matter) and pull them out. I've found a solution using charAt
methods but am particularly curious about whether it's possible to accomplish it using formatting techniques.