FizzBuzz with 4 and 6 · 4と6のFizzBuzz
FizzBuzz with 4 and 6
A FizzBuzz with a trap in it.
Test for both first, with n % 4 == 0 and n % 6 == 0. Multiplying the two numbers, n % 24 == 0, looks like a shortcut but misses 12: a number can divide by 4 and by 6 without dividing by 24.
4と6のFizzBuzz
罠が含まれたFizzBuzzです。
まずは n % 4 == 0 and n % 6 == 0 で両方の条件をチェックしてください。 2つの数を掛け合わせる n % 24 == 0 は一見近道に見えますが、 12 を見落とすことがあります: ある数が 4 と 6 の両方で割り切れても、必ずしも 24 で割り切れるとは限りません。
Print the numbers 1 to 24, one per line, but print Fizz for multiples of 4, Buzz for multiples of 6, and FizzBuzz for numbers that are multiples of both. · 1から24までの数を1行ずつ出力するが、4の倍数にはFizz、6の倍数にはBuzz、両方の倍数にはFizzBuzzを出力する。
Click Run to see the output here. · 実行ボタンをクリックして出力を確認してください。