public class FizzBuzz { public string GetOutput(int number) { var s = number % 3 == 0 ? "Fizz" : ""; if (number % 5 == 0) s += "Buzz"; return s.Length > 0 ? s : $"{number}"; // Fizz buzz is a popular computer science interview question. // The function above is given a number - if the number is // divisible by 3, return "Fizz", if it's divisible by 5, // return "Buzz", if not divisble by 3 or 5 - return the // number itself. } }
- public class FizzBuzz
- {
- public string GetOutput(int number) {
if (number % 15 == 0) return "FizzBuzz";else if (number % 3 == 0) return "Fizz";else if (number % 5 == 0) return "Buzz";else return number.ToString();- var s = number % 3 == 0 ? "Fizz" : "";
- if (number % 5 == 0) s += "Buzz";
- return s.Length > 0 ? s : $"{number}";
- // Fizz buzz is a popular computer science interview question.
- // The function above is given a number - if the number is
// divisible by 3, return "fizz", if it's divisible by 5,// return "buzz", if not divisble by 3 or 5 - return the- // divisible by 3, return "Fizz", if it's divisible by 5,
- // return "Buzz", if not divisble by 3 or 5 - return the
- // number itself.
- }
- }