- //Left Padding With Space at the start of the Number
- import java.util.*;
- import java.lang.*;
- class LeftPadwithSpace
- {
- public static void main(String[] argv) {
- System.out.println(">" + padLeft(22, 10) + "<" );
- }
- public static String padLeft(int s, int n) {
- return String.format("%0$-"+n+"d", s);
- }
- }
Output: | |
---|---|
> | 22< |