Java - Write code to repeat a string using while loop

Requirements

Write code to repeat

Demo

//package com.book2s;


public class Main {
    public static void main(String[] argv) {
        String pattern = "book2s.com";
        int count = 4;
        System.out.println(repeat(pattern, count));
    }/*from   w w  w. ja va 2 s  . c o  m*/

    public static String repeat(String pattern, int count) {
        final StringBuilder builder = new StringBuilder();
        for (int i = 0; i < count; i++) {
            builder.append(pattern);
        }
        return builder.toString();
    }
}

Related Example