ADVERTISEMENT
ADVERTISEMENT

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 »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.