Header Ad

HackerRank Ruby Tutorial - Object Methods problem solution

In this HackerRank Ruby Tutorial - Object Methods problem solution Each object in Ruby may have methods associated with it. To demonstrate this, we want you to print whether a number is even or odd. A number has an even? the method associated with it, which returns true or false based on the parity of the number.

Assuming a variable number is already defined, check whether a given number is even or not.

Input Format

The first line of input contains an integer n. The next n contains one integer in each line.

hackerrank ruby tutorial - object methods problem solution


Problem solution.

def odd_or_even(number)

    return number.even? 

end

(0...gets.to_i).each do |i|
    puts odd_or_even(gets.to_i)
end


Here above is the video that will show you the solution

Post a Comment

0 Comments