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