📜  Ruby 整数 succ()函数与示例

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

Ruby 整数 succ()函数与示例

Ruby 中的succ函数返回数字的直接后继,即返回数字 + 1 。如果使用浮点值,则会引发错误消息。

示例 1:

Ruby
# Ruby program for succ function
  
# Initializing the numbers
num1 = 100
num2 = 17
num3 = -90
num4 = -29
  
# Printing the next value
puts num1.succ
puts num2.succ
puts num3.succ
puts num4.succ


Ruby
# Ruby program for succ function
  
# Initializing the numbers
num1 = 19
num2 = -17
num3 = -18
num4 = 16
  
# Printing the succ value
puts num1.succ
puts num2.succ
puts num3.succ
puts num4.succ


输出

101
18
-89
-28

示例 2

红宝石

# Ruby program for succ function
  
# Initializing the numbers
num1 = 19
num2 = -17
num3 = -18
num4 = 16
  
# Printing the succ value
puts num1.succ
puts num2.succ
puts num3.succ
puts num4.succ

输出

20
-16
-17
17