How to add leading zeros to number in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        int num = 7;
        
        String formatted = String.format("%03d", num);

        System.out.println(formatted);
    }
}



/*
run:

007

*/

 



answered Jun 30, 2023 by avibootz
...