简体   繁体   中英

C++ setw() for Java

Is there a function in Java like setw(int) in C++?
It is needed in matrix output.

Java's java.util.Formatter class does not provide dynamic specification of field width a la setw() or printf 's dynamic width specifier * (as in %*s , which reads an argument off the list to get the width).

However, you could accomplish the same thing by making two passes, one to build the format string with the widths interpolated, and then using the format string to write the output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM