How to format integers pad with zeros into a String using String.format() in Java

1 Answer

0 votes
package javaapplication1;

public class JavaApplication1 {

    public static void main(String[] args) {

        try {

            String s = String.format("A: %05d B: %05d C: %05d", 111, 222, 333);
            System.out.println(s);

        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}

/*
             
run:

A: 00111 B: 00222 C: 00333
    
 */

 



answered Nov 29, 2016 by avibootz
...