Ruby Tutorial - Object Methods

Ruby Tutorial - Object Methods
Ruby Tutorial - Object Methods



Problem


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? 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.

Hint

Type in the code-editor

return number.even?

or

number.even?



Input Format :

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

Output Format :

The output is handled by the code written in the editor.



Solution :


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#Ruby Tutorial - Object Methods- Hacker Rank Solution
def odd_or_even(number)

    # add your code here
    number.even?

end

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





Disclaimer :-
the above hole problem statement is given by hackerrank.com but the solution is generated by the codeworld19 authority if any of the query regarding this post or website fill the following contact form thank you.

Next Post Previous Post
No Comment
Add Comment
comment url