FizzBuzz with 4 and 6 · FizzBuzz ด้วย 4 และ 6
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.
FizzBuzz ด้วย 4 และ 6
FizzBuzz ที่มีกับดักซ่อนอยู่
ทดสอบ ทั้งสอง อย่างก่อน, ด้วย n % 4 == 0 and n % 6 == 0. การคูณตัวเลขทั้งสอง, 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 บรรทัดละหนึ่ง แต่พิมพ์ Fizz สำหรับเลขที่หารด้วย 4 ลงตัว, Buzz สำหรับเลขที่หารด้วย 6 ลงตัว, และ FizzBuzz สำหรับเลขที่หารด้วยทั้งสองอย่างลงตัว
Click Run to see the output here. · คลิก Run เพื่อดูผลลัพธ์ที่นี่