zoukankan      html  css  js  c++  java
  • JDK 1.5 新特性——C风格的格式化输出

      C语言的程序猿们肯定会对这个新特性倍感亲切。

      输出一个加法算式,1.5版本以前的写法是:
      int x = 5;
      int y = 7;
      int nSum = x + y;
      System.out.println(x + " + " + y + " = " + nSum);

      而在1.5版本中可以写为:

    System.out.printf("%d + %d = %d\n", x, y, nSum);

    以上两种写法的输出结构是一样的,即“5 + 7 = 12”。

      printf还可以提供更为灵活、强大的输出功能,比如限定按照两位整数的形式输出,可以写为
    System.out.printf(”%02d + %02d = %02d\n“, x, y, nSum);

        输出结果将是“05 + 07 = 12”。

    转载请注明出处:

    博客园_yokoboy

    http://www.cnblogs.com/yokoboy/archive/2012/07/25/2608222.html

  • 相关阅读:
    Properties类
    缓冲流
    Mybatis
    分页查询
    QueryRunner和JDBC连接池
    JSP
    Session
    Cookie
    http协议和eclipes绑定tomcat
    servlet
  • 原文地址:https://www.cnblogs.com/yokoboy/p/2608222.html
Copyright © 2011-2022 走看看