Program 1:
def main
print "Hello World";
puts "Hello World";
end
Program 2:
def main
int num = 20;
string msg = "Hello World"
puts "Num: ", num;
puts "Message: ", msg;
end
main();
Program 3:
def main
num = 20;
msg = "Hello World"
puts "Num: ", num;
puts "Message: ", msg;
end
main();
Program 4:
def main
num = 20;
msg = "Hello World"
print "Num: ", num;
print "Message: ", msg;
end
main();
Program 5:
def main
num = 20;
msg = "Hello World"
println "Num: ", num;
println "Message: ", msg;
end
main();
Answer Program 1:
Output:
Explanation:
In the above program, we created a method main(), but we did not call it. That is why nothing will be printed.
Answer Program 2:
Output:
Explanation:
The above program will generate a syntax error because "int" and "string" are not any predefined datatype in ruby.
Answer Program 3:
Output:
Explanation:
In the above program, we created an integer variable num and a string variable msg. Then we printed the value of variables using the puts() method. The puts() method prints the newline by default.
Answer Program 4:
Output:
Explanation:
In the above program, we created an integer variable num and a string variable msg. Then we printed the value of variables without newline character using the print() method.
Answer Program 5:
Output:
Explanation:
The above program will generate a syntax error because println() is not a predefined method in ruby.
need an explanation for this answer? contact us directly to get an explanation for this answer