Instantly share code, notes, and snippets.

@VallaDanger VallaDanger/FizzBuzz.java
Last active Apr 22, 2016

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.

Copy link
Owner Author

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