- //Right Padding With Zero at the end of the String
- import java.util.*;
- import java.lang.*;
- class RightpadwithZero
- {
- public static void main(String[] argv) {
- String s=padRight("aaaa", 10);
- System.out.println(">" + s.replace(" ","0") + "<" );
- }
- public static String padRight(String s, int n) {
- return String.format("%0$-"+n+"s", s);
- }
- }
Output: |
---|
>aaaa000000< |