红宝石 |数字零?函数
zero?()是 Ruby 中的内置方法,返回一个布尔值。如果数字为负数,则返回 true,否则返回 false。
Syntax: num.zero?()
Parameters: The function needs a number which is to be checked for.
Return Value: It returns returns a boolean value.
示例 1 :
# Ruby program for zero?()
# method in Numeric
# Initialize a number
num1 = 0
# Prints zero or not
puts num1.zero?()
输出:
true
示例 2 :
# Ruby program for zero?()
# method in Numeric
# Initialize a number
num1 = Complex(12, 3)
# Prints zero or not
puts num1.zero?()
输出:
false