tricks

2021-10-05
87字
1分钟
  • 判断奇偶数

    //一般般
    func EvenOrOdd(number int) string {
      if number % 2 == 0 {
          return "Even"
        }
        return "Odd"
    }
    
    // 统一变量,便于操作
    func EvenOrOdd(number int) string {
      str := "Odd"
      if (number % 2 == 0) {
        str = "Even"
      }
      return str
    }
    
    //用num&1判断奇偶
    func EvenOrOdd(number int) string {
      return []string{"Even", "Odd"}[number & 1]
    }
    
Avatar
Zhang.Mathias 巧者劳而智者忧,无能者无所求,饱食而遨游,泛若不系之舟