Alernative to printf("%*s",indent,message) in java?

2.7k views Asked by At

In C we can specify the amount to space to leave in printf , any similar way to do this in java?

For example

int space=6;
char message[10]="hi";

printf("%*s",space,message);

will print

    hi
1

There are 1 answers

5
Jesper On BEST ANSWER

Create the format string dynamically:

int space = 6;
System.out.printf("%" + space + "s", "hi");