Q:

Write a Ruby program to check two non-negative integer values and return true if they have the same last digit

0

Write a Ruby program to check two non-negative integer values and return true if they have the same last digit.

All Answers

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

def string_test(str)
    str1 = ""
    str.split("").each_with_index do |char, index|
        str1 += char unless index % 2 == 1     
    end
    return str1
end
print string_test('abcdefgij'),"\n"
print string_test('abcdefg'),"\n"
print string_test('abcdef'),"\n"
print string_test('abc'),"\n"
print string_test('ab'),"\n"
Output:
acegj
aceg
ace
ac
a

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

total answers (1)

Similar questions


need a help?


find thousands of online teachers now