Skip to content

Instantly share code, notes, and snippets.

@phl0w
Created July 8, 2012 17:26
Show Gist options
  • Select an option

  • Save phl0w/3071917 to your computer and use it in GitHub Desktop.

Select an option

Save phl0w/3071917 to your computer and use it in GitHub Desktop.
public class ProgrammingChallenge {
public static void main(String... args) {
System.out.println(stringTimes("Hi", 5));
}
public static String stringTimes(String str, int n) {
StringBuilder sb = new StringBuilder();
if (n <= 0) {
System.err.println("n must be > 0");
} else {
for (int i = 0; i < n; i++) {
sb.append(str);
}
}
return sb.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment