ADVERTISEMENT
ADVERTISEMENT

Ruby program to compare numbers and strings using library function

Ruby Example: Write a program to compare numbers and strings using library function.
Submitted by Nidhi, on December 15, 2021

Problem Solution:

In this program, we will create some variables. Then we will compare numbers and strings using library function eql?(). The eql?() function returns Boolean value true or false after comparison.

Program/Source Code:

The source code to compare numbers and strings using the library function is given below. The given program is compiled and executed successfully.

# Ruby program to compare numbers and 
# strings using library function

num1 = 22;
num2 = 3;
num3 = 3;

str1 = "hello";
str2 = "hello";
str3 = "hi";

print num1.eql?(num2),"\n";
print num2.eql?(num3),"\n";

print str1.eql?(str2),"\n";
print str2.eql?(str3),"\n";

Output:

false
true
true
false

Explanation:

In the above program, we created some variables. Then we performed a comparison between numbers and strings using the eql?() function and printed the returned Boolean value.

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.