Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class FizzBuzz {
- public static void main(String[] args) throws Throwable{
- for (int i=1; i< 77; i++) System.out.println(fizzBuzz(i));
- //new String[]{String.valueOf(n), "Fizz", "Buzz", "FizzBuzz"}[(-n%3 >>> 31 ^ 1) + ((-n%5 >>> 31 ^ 1) << 1)];
- }
- static String fizzBuzz(int n) {
- String[] s = {String.valueOf(n), "Fizz", "Buzz", "FizzBuzz"};//note String.valueOf(n) is not constant time, see http://pastebin.com/GdsAXKnv
- int f = -n%3 >>> 31 ^ 1;//one when n%3 == 0 (uses the 'sign' bit)
- int b = (-n%5 >>> 31 ^ 1) << 1;
- return s[f+b];
- }
- }
Add Comment
Please, Sign In to add comment