📜  红宝石 |正数?函数

📅  最后修改于: 2022-05-13 01:55:34.027000             🧑  作者: Mango

红宝石 |正数?函数

positive?()是 Ruby 中的一个内置方法,返回一个布尔值。如果数字是正数,则返回 true,否则返回 false。

示例 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