红宝石 |数值 abs2()函数
abs2()是 Ruby 中的内置方法,返回数字的平方。
Syntax: num.abs2
Parameters: The function needs the number whose square is to be returned.
Return Value: It returns the square of a number.
示例 1 :
Ruby
# Ruby program for abs2() method in Numeric
# Initialize a number
num = -19
# Prints square of num
puts num.abs2()
Ruby
# Ruby program for abs2() method in Numeric
# Initialize a number
num = 100
# Prints square of num
puts num.abs2()
输出:
361
示例 2 :
红宝石
# Ruby program for abs2() method in Numeric
# Initialize a number
num = 100
# Prints square of num
puts num.abs2()
输出:
10000