使用类Formatter格式化输出。
/* n o w j a v a . c o m - 时代Java */ import java.util.Formatter; import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { // create Formatter and format output Formatter formatter = new Formatter(); formatter.format("%d = %#o = %#X", 10, 10, 10); // display output in JOptionPane JOptionPane.showMessageDialog(null, formatter.toString()); } }