目的: 把1位数的整数输出为字符串形式, 如 01, 02 等.多谢只有20分了.

解决方案 »

  1.   

    方法1: 使用DecimalFormat DecimalFormat df = new DecimalFormat("00");
    System.out.println(df.format(intValue));方法2:
    String v = "00" + intValue;
    System.out.println( v.substring(v.length-2));
      

  2.   

    public class NumToString {
    public static void main(String[] args) {
    for (int i=1; i<=9; i++) {
    System.out.println("0"+i);
    }
    }
    }
      

  3.   

    int a = 1;
    String s = "0"+a;
      

  4.   

    int k = 1;
    String s = String.format("%02d", k);
      

  5.   

    忘记说了,如果需要三位数或其他更多的长度,只要将 %02d 中的 2 改为其他的数就行了。JDK 1.5 新加的挺方便的。
      

  6.   

    String v = "00" + intValue;
    System.out.println( v.substring(v.length-2));