Java - Write code to blank Pad a string

Requirements

Write code to blank Pad a string

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String sp = "book2s.com";
        int totl = 42;
        System.out.println(blankPad(sp, totl));
    }//from   w  w w . j av  a 2 s.co  m

    public static String blankPad(String sp, int totl) {
        StringBuffer sb = new StringBuffer();
        int nta = totl - sp.length();
        sb.append(sp);
        for (int i = 0; i < nta; i++) {
            sb.append(" ");
        }
        return sb.toString();
    }
}