Introducing Radical.sh

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

Left Padding with space at the start of number in Java

  1. //Left Padding With Space at the start of the Number
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5.  
  6. class LeftPadwithSpace
  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. }


Output:
>22<