控制台数据格式化输出

 1 package com.baidu.com;
 2 
 3 import java.util.Formatter;
 4 
 5 public class Testformat {
 6     static Formatter formatter = new Formatter(System.out);
 7     public static void main(String[] args) {
 8         // TODO Auto-generated method stub
 9         formatter.format("%-15s %5d %10.2f\n", "My name is huhx", 5, 4.2);
10         formatter.format("%-15.4s %5d %10.2f\n", "My name is huhx", 5, 4.1);
11         formatter.format("|%-25s|%-5d|%-10.2f|\n", "My huhx", 5, 4.1);
12         formatter.format("|%-25s|%-5d|%-10.2f|\n", "My name is huhx", 5, 4.1);
13         formatter.format("|%-25s|%-5d|%-10.2f|\n", "huhx", 5, 4.1);
14         formatter.format("|%-25s|%-5d|%-10.2f|\n", "My name is huhx", 5, 4.1);
15     }
16 
17 }

猜你喜欢

转载自www.cnblogs.com/wujianbo123/p/12301184.html