How can I store an integer in two digit format in Java? Like can I set
int a=01;
and print it as 01? Also, not only printing, if I say int b=a;, b should also print its value as 01.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think this is what you’re looking for:
Or, more briefly:
An int just stores a quantity, and 01 and 1 represent the same quantity so they’re stored the same way.
DecimalFormat builds a String that represents the quantity in a particular format.