import static java.lang.System.out;

Simple two-liner:

static void f(int a, int z) {
	out.println(a % 15 < 1 ? "FizzBuzz" : a % 3 < 1 ? "Fizz" : a % 5 < 1 ? "Buzz" : a);
	if (a < z) f(1 + a, z);
}

Without using the literal “FizzBuzz”:

static void g(int a, int z) {
	int x = 0;
	if (a % 3 < 1 && ++x > 0) out.print("Fizz");
	if (a % 5 < 1 && ++x > 0) out.print("Buzz");
	if (x < 1) out.print(a);
	out.println();
	if (a < z) g(1 + a, z);
}

Note that I use x<1 instead of x==0 to save a single character.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s