怎样将整形 4 输出成0004 的字符串形式

解决方案 »

  1.   

    我是不是需要根据这个
    数字是<10 前面加 000
    >10 && <100 前面加   00
    >100 && <1000 前面加   0
    >1000 前面不加.
    有没好的方式.
    这么土的方法,就不用告诉我了.
      

  2.   

    import java.text.DecimalFormat;System.out.println(new DecimalFormat("0000").format(1));
      

  3.   

    String itoa(int n)
    {
      char a[]=new char[4];
      for(int i=0; i<4; i++){
        a[i] = (n%10)+'0';
        n /= 10;
      }
      return new String(a);
    }
      

  4.   

    rcom10002(KNIGHTRCOM)提供的方式才是我想要的.