Java tutorial
//package com.java2s; import java.util.Arrays; public class Main { public static String repeat(String s, int n) { if (s.length() == 1) { byte[] bb = new byte[n]; Arrays.fill(bb, s.getBytes()[0]); return new String(bb); } else { StringBuilder ret = new StringBuilder(); for (int i = 0; i < n; i++) ret.append(s); return ret.toString(); } } }