Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to pad integers with zeros and a width of N places using String.format() in Java

1 Answer

0 votes
package javaapplication1;

import java.io.IOException;

public class JavaApplication1 {

    public static void main(String[] args) throws IOException {

        try {

            for (int i = 0; i < 10; i++) {
                String result = String.format("%1$06d %2$06d", i, i * 10);
                System.out.println(result);
            }

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

/*
           
run:
     
000000 000000
000001 000010
000002 000020
000003 000030
000004 000040
000005 000050
000006 000060
000007 000070
000008 000080
000009 000090
  
 */

 



answered Nov 19, 2016 by avibootz

Related questions

3 answers 257 views
2 answers 132 views
1 answer 162 views
1 answer 144 views
...