@@ -0,0 +1,3292 @@
+package leetcode.concurrency;%0A%0Aimport java.util.concurrent.atomic.AtomicInteger;%0Aimport java.util.function.IntConsumer;%0A%0Apublic class FizzBuzz %7B%0A%0A    private int n;%0A    private AtomicInteger counter = new AtomicInteger(1);%0A    public FizzBuzz(int n) %7B%0A        this.n = n;%0A    %7D%0A%0A    public void fizz(Runnable printFizz) throws InterruptedException %7B%0A        while (true) %7B%0A            int i = counter.get();%0A            if (i %3E n) %7B%0A                break;%0A            %7D%0A            if (i %25 3 == 0 && i %25 5 != 0) %7B%0A                printFizz.run();%0A                counter.incrementAndGet();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void buzz(Runnable printBuzz) throws InterruptedException %7B%0A        while (true) %7B%0A            int i = counter.get();%0A            if (i %3E n) %7B%0A                break;%0A            %7D%0A            if (i %25 5 == 0 && i %25 3 != 0) %7B%0A                printBuzz.run();%0A                counter.incrementAndGet();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void fizzbuzz(Runnable printFizzBuzz) throws InterruptedException %7B%0A        while (true) %7B%0A            int i = counter.get();%0A            if (i %3E n) %7B%0A                break;%0A            %7D%0A            if (i %25 15 == 0) %7B%0A                printFizzBuzz.run();%0A                counter.incrementAndGet();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public void number(IntConsumer printNumber) throws InterruptedException %7B%0A        while (true) %7B%0A            int i = counter.get();%0A            if (i %3E n) %7B%0A                break;%0A            %7D%0A            if (i %25 3 != 0 && i %25 5 != 0) %7B%0A                printNumber.accept(i);%0A                counter.incrementAndGet();%0A            %7D%0A        %7D%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws InterruptedException %7B%0A        FizzBuzz fizzBuzz = new FizzBuzz(15);%0A        Thread fizz = new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A                    fizzBuzz.fizz(() -%3E System.out.print(%22fizz%22));%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D);%0A        Thread buzz = new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A                    fizzBuzz.buzz(() -%3E System.out.print(%22buzz%22));%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D);%0A        Thread fizzbuzz = new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A                    fizzBuzz.fizzbuzz(() -%3E System.out.print(%22fizzbuzz%22));%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D);%0A        Thread number = new Thread(new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A                try %7B%0A                    fizzBuzz.number(System.out::print);%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A        %7D);%0A%0A        fizz.start();%0A        buzz.start();%0A        fizzbuzz.start();%0A        number.start();%0A%0A%0A        fizz.join();%0A        buzz.join();%0A        fizzbuzz.join();%0A        number.join();%0A    %7D%0A%7D%0A

Add FizzBuzz