Fetch the repository succeeded.
This action will force synchronization from 小墨/力扣题库(完整版), which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
<p>You have the four functions:</p>
<ul>
<li><code>printFizz</code> that prints the word <code>"fizz"</code> to the console,</li>
<li><code>printBuzz</code> that prints the word <code>"buzz"</code> to the console,</li>
<li><code>printFizzBuzz</code> that prints the word <code>"fizzbuzz"</code> to the console, and</li>
<li><code>printNumber</code> that prints a given integer to the console.</li>
</ul>
<p>You are given an instance of the class <code>FizzBuzz</code> that has four functions: <code>fizz</code>, <code>buzz</code>, <code>fizzbuzz</code> and <code>number</code>. The same instance of <code>FizzBuzz</code> will be passed to four different threads:</p>
<ul>
<li><strong>Thread A:</strong> calls <code>fizz()</code> that should output the word <code>"fizz"</code>.</li>
<li><strong>Thread B:</strong> calls <code>buzz()</code> that should output the word <code>"buzz"</code>.</li>
<li><strong>Thread C:</strong> calls <code>fizzbuzz()</code> that should output the word <code>"fizzbuzz"</code>.</li>
<li><strong>Thread D:</strong> calls <code>number()</code> that should only output the integers.</li>
</ul>
<p>Modify the given class to output the series <code>[1, 2, "fizz", 4, "buzz", ...]</code> where the <code>i<sup>th</sup></code> token (<strong>1-indexed</strong>) of the series is:</p>
<ul>
<li><code>"fizzbuzz"</code> if <code>i</code> is divisible by <code>3</code> and <code>5</code>,</li>
<li><code>"fizz"</code> if <code>i</code> is divisible by <code>3</code> and not <code>5</code>,</li>
<li><code>"buzz"</code> if <code>i</code> is divisible by <code>5</code> and not <code>3</code>, or</li>
<li><code>i</code> if <code>i</code> is not divisible by <code>3</code> or <code>5</code>.</li>
</ul>
<p>Implement the <code>FizzBuzz</code> class:</p>
<ul>
<li><code>FizzBuzz(int n)</code> Initializes the object with the number <code>n</code> that represents the length of the sequence that should be printed.</li>
<li><code>void fizz(printFizz)</code> Calls <code>printFizz</code> to output <code>"fizz"</code>.</li>
<li><code>void buzz(printBuzz)</code> Calls <code>printBuzz</code> to output <code>"buzz"</code>.</li>
<li><code>void fizzbuzz(printFizzBuzz)</code> Calls <code>printFizzBuzz</code> to output <code>"fizzbuzz"</code>.</li>
<li><code>void number(printNumber)</code> Calls <code>printnumber</code> to output the numbers.</li>
</ul>
<p> </p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> n = 15
<strong>Output:</strong> [1,2,"fizz",4,"buzz","fizz",7,8,"fizz","buzz",11,"fizz",13,14,"fizzbuzz"]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> n = 5
<strong>Output:</strong> [1,2,"fizz",4,"buzz"]
</pre>
<p> </p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= n <= 50</code></li>
</ul>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。