ADVERTISEMENT
ADVERTISEMENT

Ruby program to compare two arrays using the eql?() method

Ruby Example: Write a program to compare two arrays using the eql?() method.
Submitted by Nidhi, on January 14, 2022

Problem Solution:

In this program, we will create three arrays of integers then we will compare arrays using the eql?() method and print the appropriate message.

Program/Source Code:

The source code to compare two arrays using the eql?() method is given below. The given program is compiled and executed successfully.

# Ruby program to compare two arrays 
# using eql?() method

arr1 = [10,20,30,20,50,30];
arr2 = [10,50,30,40,60,70];
arr3 = [10,20,30,20,50,30];

if arr1.eql?(arr2)
    print "arr1 and arr2 are equal.\n";
else
    print "arr1 and arr2 are not equal.\n";
end

if arr1.eql?(arr3)
    print "arr1 and arr3 are equal.\n";
else
    print "arr1 and arr3 are not equal.\n";
end

Output:

arr1 and arr2 are not equal.
arr1 and arr3 are equal.

Explanation:

In the above program, we created 3 arrays arr1, arr2, arr3 with some elements. Then we compared arrays using the eql?() method and printed the appropriate message.

Ruby Arrays 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.