how I can rewrite this:
for (int i = 0; i < numberOfSpaces; i++) {
System.out.print(" ");
}
using String.format()?
PS
I’m pretty sure that this is possible but the javadoc is a bit confusing.
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 need to specify the minimum width of the field.
Why do you want to generate a String of spaces of a certain length.
If you want a column of this length with values then you can do:
which gives you numberOfSpaces-5 spaces followed by Hello. If you want Hello to appear on the left then add a minus sign in before numberOfSpaces.