Q:

Ruby program to print Hello World!

belongs to collection: Ruby Miscellaneous Programs

0

To print text (Hello World! Or anything else), we use following two methods,

  1. puts : The word "puts" stands for put string. It adds a newline after the string.
  2. print : The functionality of this method is same as of puts but it does not adds newlines implicitly like puts.

Variables used: No variables are required as we only have to print the statements. We don't have to store anything.

All Answers

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

Ruby code to print "Hello World!"

=begin 
Ruby program to print Hello World.
=end

puts "Hello World!"
print "Hello World!"
puts "Hello World!"

Output

Hello World!
Hello World!Hello World!

Code explanation:

The code illustrates an example to print a string "Hello World!" in Ruby programming language. This uses the puts and print methods to print the string and output "Hello world" using these methods.

You can observe in the output that the print method is not providing a newline and two statements are printing together. Though, both the methods have the same functionality but still use them wisely.

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

total answers (1)

Ruby program to add two integer numbers... >>