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));
    }//  ww  w.  j av a  2s . 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