Java - Write code to multiply a string with for loop and StringBuffer

Requirements

Write code to multiply a string with for loop and StringBuffer

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(multiply(s));
    }/* w w  w .j a va2  s .c  o m*/

    public static String multiply(String s) {
        return multiply(s, 5);
    }

    public static String multiply(String s, int count) {
        StringBuffer buffer = new StringBuffer(25);

        for (int i = 0; i <= count; i++) {
            buffer.append(s);
        }

        return buffer.toString();
    }
}

Related Example