Skip to content

Instantly share code, notes, and snippets.

@yaotti
Created December 23, 2010 12:39
Show Gist options
  • Save yaotti/752911 to your computer and use it in GitHub Desktop.
Save yaotti/752911 to your computer and use it in GitHub Desktop.
public class FizzBuzz {
public int max;
FizzBuzz(int n) {
max = n;
}
FizzBuzz() {
max = 100;
}
public void show() {
for (int i = 1; i <= max; i++) {
if (i%3 == 0) {
System.out.print("Fizz");
}
if (i%5 == 0) {
System.out.print("Buzz");
}
if ((i%3) * (i%5) != 0) {
System.out.print(i);
}
System.out.print(i == max ? "\n" : ",");
}
}
public static void main(String[] args) {
FizzBuzz fb_100 = new FizzBuzz();
fb_100.show();
FizzBuzz fb_10 = new FizzBuzz(10);
fb_10.show();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment