Instantly share code, notes, and snippets.

Embed
What would you like to do?
FizzBuzz Java (recursive)
public class Main {
public static void main(String[] args) throws Exception {
System.out.println(getText(new StringBuilder("1,2,"), 3));
}
private static StringBuilder build(StringBuilder sb, int i) {
if(i%3 == 0) {
sb.append("Fizz");
}
if(i%5 == 0) {
sb.append("Buzz");
} else if(i%3 != 0) {
sb.append(i);
}
return (i < 100) ? build(sb.append(','), ++i) : sb;
}
}
@VallaDanger

This comment has been minimized.

Show comment
Hide comment
@VallaDanger

VallaDanger Apr 22, 2016

yet another way to solve the FizzBuzz problem

Owner

VallaDanger commented Apr 22, 2016

yet another way to solve the FizzBuzz problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment