×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to check the given number is an integer or not

Last Updated : December 15, 2025

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!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.