I generate a random number between 0-99 using this :
int num2= (int)(Math.random() * ((99) + 1));
When the number is below 10 I want it to print with a 0num2
So if the number is 9 it would be 09.
How can I get it to print this?
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.
You can use the
format()method:%02dprints the argument as a number with width 2, padded with 0’s%ngives you a newline