控制台数据格式化输出

 

 

 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 }

 

posted @ 2020-02-12 21:54  18513757531  阅读(379)  评论(0编辑  收藏  举报