Declare an extra variable before using printf
:
String format = "%" + fieldSize + "d";
System.out.printf(format, yourVariables);
(this is the first solution I found from a web search)
More Related Contents:
- A beginner questions about printf, java
- Change date format in a Java string
- How to print a float with 2 decimal places in Java?
- How to format a Java string with leading zero?
- How to convert current date into string in java?
- formatting a string to a currency format in jasper report
- Sprintf equivalent in Java
- Print out elements from an Array with a Comma between the elements
- Generate fixed length Strings filled with whitespaces
- How can I remove punctuation from input text in Java?
- How to use String.format() in Java? [duplicate]
- how to do substring of HttpResponse in android
- How to replace a char with a string
- How do I create a Java string from the contents of a file?
- How to nicely format floating numbers to string without unnecessary decimal 0’s
- Java – Convert integer to string [duplicate]
- How to remove line breaks from a file in Java?
- How can I get the size of an array, a Collection, or a String in Java?
- How to remove duplicate white spaces in string using Java?
- Isn’t the size of character in Java 2 bytes?
- Converting an int to a binary string representation in Java?
- Difference between “char” and “String” in Java
- Fatal Error: Invalid Layout of java.lang.String at value
- String replacement in java, similar to a velocity template
- How to center a string using String.format?
- Read String line by line
- How to get the last characters in a String in Java, regardless of String size
- substring index range
- How to replace � in a string
- Compare two hex strings in Java?