Skip to content

Instantly share code, notes, and snippets.

@jaredcacurak
Created January 20, 2011 15:19
Show Gist options
  • Select an option

  • Save jaredcacurak/788040 to your computer and use it in GitHub Desktop.

Select an option

Save jaredcacurak/788040 to your computer and use it in GitHub Desktop.
An implementation of the FizzBuzz.
package com.rocketpush.puzzle;
public class FizzBuzz {
public static String fizzBuzz(boolean isFizzy, boolean isBuzzy, int i) {
String value = String.valueOf(i);
if (isFizzy && isBuzzy) {
value = "FizzBuzz";
} else if (isFizzy) {
value = "Fizz";
} else if (isBuzzy) {
value = "Buzz";
}
return value;
}
public static void main(String... args) {
for (int i = 1; i <= 100; i += 1) {
boolean isFizzy = i % 3 == 0;
boolean isBuzzy = i % 5 == 0;
String result = fizzBuzz(isFizzy, isBuzzy, i);
System.out.println(result);
}
}
}
@jaredcacurak

Copy link
Copy Markdown
Author

Watch me code at Interview Zen http://www.interviewzen.com/interview/bStyy via @interviewzen

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