Java - Write code to create String by repeating a char

Requirements

Write code to create String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        char ch = 'a';
        int count = 42;
        System.out.println(createString(ch, count));
    }/*from   w  w  w .ja v a2  s .c o m*/

    public static String createString(char ch, int count) {
        StringBuilder result = new StringBuilder(count);

        for (int index = 0; index < count; index++) {
            result.append(ch);
        }

        return result.toString();
    }
}

Related Exercise