Skip to content · ⁨コンテンツへスキップ⁩

FizzBuzz

English

FizzBuzz

The classic. Walk the numbers 1 to n and, for each, decide what string to add to a list:

  • divisible by both 3 and 5 → FizzBuzz
  • divisible by 3 → Fizz
  • divisible by 5 → Buzz
  • otherwise → the number itself, as a string

Check the "both" case first, or a multiple of 15 will be caught by the 3 test alone.

日本語

FizzBuzz

古典的な問題です。1 から n までの数を巡り、それぞれに対してリストに追加する文字列を決定します:

  • 3でも5でも割り切れる → FizzBuzz
  • 3で割り切れる → Fizz
  • 5で割り切れる → Buzz
  • その他 → 数字自体を文字列として

「両方」の場合を最初にチェック不然、15の倍数は3で割れるテストだけで判定されてしまいます。

Log in or create account · ⁨ログインまたはアカウント作成⁩

IGCSE, A-Level & AP