How can I pad an integer with zeros on the left?

后端 未结 16 2265
南旧
南旧 2020-11-21 06:31

How do you left pad an int with zeros when converting to a String in java?

I\'m basically looking to pad out integers up to 9999

16条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-21 06:53

    int x = 1;
    System.out.format("%05d",x);
    

    if you want to print the formatted text directly onto the screen.

提交回复
热议问题