Created
December 23, 2010 12:39
-
-
Save yaotti/752911 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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