Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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 arr1arr2arr3 with some elements. Then we compared arrays using the eql?() method and printed the appropriate message.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now