Skip to content

Instantly share code, notes, and snippets.

@VallaDanger
Last active April 22, 2016 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VallaDanger/3561e62d8b328d003ebaf3676476d765 to your computer and use it in GitHub Desktop.
Save VallaDanger/3561e62d8b328d003ebaf3676476d765 to your computer and use it in GitHub Desktop.
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
Copy link
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