w3resource

Ruby Basic Exercises: Print the elements of a given array

Ruby Basic: Exercise-29 with Solution

Write a Ruby program to print the elements of a given array.

Ruby Basic Exercises: Print the elements of a given array

Sample array : ["Ruby", 2.3, Time.now]

Ruby Code:

array1 = ["Ruby", 2.3, Time.now]
for array_element in array1
          puts array_element
end

Output:

Ruby
2.3
2017-12-28 06:01:53 +0000

Flowchart:

Flowchart: Print the elements of a given array

Ruby Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Ruby program to print odd numbers from 10 to 1.
Next: Write a Ruby program to check two non-negative integer values and return true if they have the same last digit.

What is the difficulty level of this exercise?



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/ruby-exercises/basic/ruby-basic-exercise-29.php