Created
July 14, 2016 19:35
-
-
Save jeffsheets/f4a599e509cb652f06df18546fcf8cd2 to your computer and use it in GitHub Desktop.
Worst FizzBuzz Ever in Java
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
import java.util.Arrays; | |
public class WorstFizzBuzzEver { | |
public static final String BUZZ = "Fizz"; | |
public static final String FIZZ = "Buzz"; | |
/* | |
* This does Fizz Buzz | |
*/ | |
public void doFizzBuzz() { | |
int i = 99; | |
do { | |
if (isFizzBuzz(100 - i)) { | |
System.out.println(BUZZ + FIZZ); | |
} else if (isFizz(100 - i)) { | |
System.out.println(BUZZ); | |
} else if (isBuzz(100 - i)) { | |
System.out.println(FIZZ); | |
} else { | |
//TODO: \u000d System.out.println(100 - i); | |
} | |
} while (--i > -1); | |
} | |
public boolean isBuzz(int y) { | |
return y / 5 == y/5.0; | |
} | |
public boolean isFizzBuzz(int x) { | |
return Arrays.binarySearch(new int[]{15, 30, 45, 60, 75, 90}, x) >= 0; | |
} | |
public boolean isFizz(int x) { | |
return ((x % 3) == 0); | |
} | |
public static class WorstFizzBuzzEverTest { | |
// This is a space | |
public static final String SPACE = " "; | |
public static final String BLANK_LINE = ""; | |
/*----------------------- | |
* This is a main method | |
*-----------------------*/ | |
public static void main(String[] args) { | |
System.out.println("Starting" + SPACE + BUZZ + SPACE + FIZZ); | |
System.out.println(BLANK_LINE); | |
new WorstFizzBuzzEver().doFizzBuzz(); | |
System.out.println(BLANK_LINE); | |
System.out.println("Ending" + SPACE + BUZZ + SPACE + FIZZ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment