-
-
Save wmoxam/b9a81c8ea4ec76abe1cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Q: In Ruby, the max method returns the largest number in an array of integers. Ex: | |
[14, 23, 6, 9, 54, 10].max #=> 54 | |
Write an implementation of the max method that accepts an array as it's argument. Do not use the existing .max method | |
class Testing | |
puts "enter five number to check the greatest among from that." | |
a = gets.chomp | |
b = gets.chomp | |
c = gets.chomp | |
d = gets.chomp | |
e = gets.chomp | |
array = [] | |
array << a.to_i | |
array << b.to_i | |
array << c.to_i | |
array << d.to_i | |
array << e.to_i | |
def self.message(arr) | |
arr.sort.last | |
end | |
puts "the greatest number among the entered number is " + "#{message(array) }" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment