Home »
Ruby »
Ruby Programs
Ruby program to check the given number is an integer or not
Ruby Example: Write a program to check the given number is an integer or not.
Submitted by Nidhi, on December 11, 2021
Problem Solution:
In this program, we will create some variables with some initial values and check given numbers are integer or not using "integer?".
Program/Source Code:
The source code to check given number is an integer or not is given below. The given program is compiled and executed successfully.
# Ruby program to check the given
# number is an integer or not
num1 = 12.34;
num2 = -100;
num3 = 400;
print "Num1: " ,num1.integer?;
print "\nNum2: ",num2.integer?;
print "\nNum3: ",num3.integer?;
Output:
Num1: false
Num2: true
Num3: true
Explanation:
In the above program, we created three variables num1, num2, num3 initialized with 12.34, -100, 400 respectively. Then we checked given numbers are integer or not using integer? and printed the result.
Ruby Basic Programs »