13.5 格式化输出

来源:互联网 发布:知花作品全集 编辑:程序博客网 时间:2024/06/10 19:00
package com.cnsuning.src;public class Main {public Main() {// TODO Auto-generated constructor stub}public static void main(String[] args) {Main m = new Main();m.testPrintF();}public String toString(){//这里不能使用this来作为当前地址输出, 因为编译器会调用this.toString进行类型转换, 其结果就是循环调用, 会产生异常return "class address is "+super.toString();}public void testPrintF(){System.out.printf("test is [%d,%f]",2,5.3);System.out.format("test is [%d,%f]",2,5.3);}}

test is [2,5.300000]test is [2,5.300000]
0 0