Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Left Padding with zeros at the start of Number in Java

  1. //Right Padding With Zero at the start of the Number
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5.  
  6. class LeftpadWithZero
  7. {
  8. public static void main(String[] argv) {
  9. System.out.println(">" + padLeft(22, 10) + "<" );
  10. }
  11.  
  12. public static String padLeft(int s, int n) {
  13. return String.format("%0"+n+"d", s);
  14. }
  15. }
  16.  


Output:
>0000000022<