Example: #1 - Swapping of two numbers using temporary variable
Ruby Input Screen
class SwapExample
def swapNumbers
a = 3
b = 6
puts("The value of a before swap is " + a.to_s)
puts("The value of b before swap is " + b.to_s)
# Swapping of two numbers using temp variable
temp = a
a = b
b = temp
puts("The value of a after swap is " + a.to_s)
puts("The value of b after swap is " + b.to_s)
end
end
obj = SwapExample.new
obj.swapNumbers
Ruby Output Screen
The value of a before swap is 3
The value of b before swap is 6
The value of a after swap is 6
The value of b after swap is 3