Ad

A simple FizzBuzz implementation, to try out Kumites.

Take a positive integer as input, and output:

"Fizz" if the number is divisible by three
"Buzz" if the number is divisible by five
"FizzBuzz" if the number is divisible by three and five
otherwise, just the number (as a string)

Code
Diff
  • using System;
    
    namespace Solution {
    
      class FizzBuzz {
        public static string convert(int input)
            {
                var output = (input % 3 == 0 ? "Fizz" : "") + (input % 5 == 0 ? "Buzz" : "");
    
                return output == "" ? input.ToString() : output;
            }
      }
    }
    • using System;
    • namespace Solution {
    • class FizzBuzz {
    • public static string convert(int input)
    • {
    • var output = "";
    • var output = (input % 3 == 0 ? "Fizz" : "") + (input % 5 == 0 ? "Buzz" : "");
    • output += (input % 3 == 0) ? "Fizz" : "";
    • output += (input % 5 == 0) ? "Buzz" : "";
    • output += (string.IsNullOrEmpty(output)) ? input.ToString() : "";
    • return output;
    • return output == "" ? input.ToString() : output;
    • }
    • }
    • }

A simple FizzBuzz implementation, to try out Kumites.

Take a positive integer as input, and output:

  • "Fizz" if the number is divisible by three
  • "Buzz" if the number is divisible by five
  • "FizzBuzz" if the number is divisible by three and five
  • otherwise, just the number (as a string)
using System;

namespace Solution {

  class FizzBuzz {
    public static string convert(int input){
    
      if (input % 3 == 0 && input % 5 == 0) {
        return "FizzBuzz";
      }
    
      if (input % 3 == 0) {
        return "Fizz";
      }
      
      if (input % 5 == 0) {
        return "Buzz";
      }
      
      return input.ToString();
    }
  }
}