Write a fizzbuzz implementation in Scala
- User
Write a fizzbuzz implementation in Scala
Assistant
Sure! Here's a FizzBuzz implementation in Scala:
object FizzBuzz { def main(args: Array[String]): Unit = { for (i <- 1 to 100) { if (i % 3 == 0 && i % 5 == 0) { println("FizzBuzz") } else if (i % 3 == 0) { println("Fizz") } else if (i % 5 == 0) { println("Buzz") } else { println(i) } } } }This program uses a for loop to iterate over the numbers 1 to 100. For each number, it checks if it's divisible by 3, 5, or both using the modulo operator
%. If it is, it prints the corresponding word ("Fizz", "Buzz", or "FizzBuzz"). If not, it just prints the number itself.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.