The source code to compare two strings using the Equal To (==) operator is given below. The given program is compiled and executed successfully.
# Ruby program to compare two strings
# using the Equal To (==) operator
Str1 = "Hello";
Str2 = "hello";
Str3 = "Hello";
if (Str1 == Str2)
print "Str1 and Str2 are equal\n";
else
print "Str1 and Str2 are not equal\n";
end
if (Str1 == Str3)
print "Str1 and Str3 are equal\n";
else
print "Str1 and Str3 are not equal\n";
end
Output:
Str1 and Str2 are not equal
Str1 and Str3 are equal
Explanation:
In the above program, we created 3 variables Str1, Str2, Str3 that are initialized with "Hello", "hello", "Hello". Then we compared string variables using the Equal To (==) operator and printed the appropriate message.
Program/Source Code:
The source code to compare two strings using the Equal To (==) operator is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created 3 variables Str1, Str2, Str3 that are initialized with "Hello", "hello", "Hello". Then we compared string variables using the Equal To (==) operator and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer