Create a gist now

Instantly share code, notes, and snippets.

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;
}
}
Owner

VallaDanger commented Apr 22, 2016 edited

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