Generic selectors
Exact matches only
Search in title
Search in content
Search in posts
Search in pages
Filter by Categories
nmims post
Objective Type Set
Online MCQ Assignment
Question Solution
Solved Question
Uncategorized

1. The .upcase and .capitalize method are used for capitalizing the whole string.
a) True
b) False

View Answer

Answer: b [Reason:] The .capitalize method doesn’t change the whole string to uppercase, it just capitalizes the first letter.

2. What is the use of .capitalize method?
a) It capitalizes the entire string
b) It capitalize on the first letter of the string
c) It capitalize the strings which are in small case
d) All of the mentioned

View Answer

Answer: b [Reason:] It capitalizes only the first letter.

3. What is the role of ! at the end of the capitalize method?
a) It is the syntax for using capitalize method
b) It modifies the value stored in the variable
c) It indicates the termination of string
d) None of the mentioned

View Answer

Answer: b [Reason:] It is used for modifying the variable.

4. What is the output of the code?

print "What's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   first_name.capitalize!
   print "What's your last name?"
   last_name=gets.chomp
   b=last_name.capitalize
   last_name.capitalize!
   puts "My name is #{first_name} #{last_name}"

a) Amil Jones
b) What’s your first name? amil
What’s your last name? jones
My name is Amil Jones
c) My name is Amil Jones
d) None of the mentioned

View Answer

Answer: b [Reason:] First it takes the input from user and then modifies accordingly and displays output.

Output:
What's your first name? amil
What's your last name? jones
My name is Amil Jones

5. What is the output of the code?

print "What's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   first_name.capitalize!
   print "What's your last name?"
   last_name=gets.chomp
   b=last_name.capitalize
   last_name.capitalize
   puts "My name is #{first_name} #{last_name}"

a) Amil Jones
b) What’s your first name? amil
What’s your last name? jones
My name is Amil Jones
c) What’s your first name? amil
What’s your last name? jones
My name is Amil jones
d) None of the mentioned

View Answer

Answer: b [Reason:] Capitalize method was not called at the time of last name, jones was not printed correctly it was not modified because ! was not used.

Output :
What's your first name? amil
What's your last name? jones
My name is Amil jones

6. What is the output of the given code?

print "what's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   "first_name.capitalize!".reverse
   puts"My name is #{first_name}"

a) amil jones
b) What’s your first name? amil
My name is amil
c) My name is lima
d) My name is limA

View Answer

Answer: b [Reason:] “first_name.capitalize!” can not be in double quotes because it is a method.

Output:
What's your first name? amil
My name is amil

7. What is the output of the given code?

print "what's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   "a".reverse
   puts"My name is #{a}"

a) amil jones
b) What’s your first name? amil
My name is Amil
c) My name is lima
d) My name is limA

View Answer

Answer: b [Reason:] The string is reversed but it is not stored in any variable.

Output:
What's your first name? amil
My name is amil

8. What is the output of the given code?

 print "What's your first name?"
   first_name=gets.chomp
   a=first_name.capitalize
   a=a.reverse
   puts"My name is #{a}"

a) amil jones
b) What’s your first name? amil
My name is Amil
c) What’s your first name? amil
My name is limA
d) My name is limA

View Answer

Answer: b [Reason:] The string is reversed then and stored in a variable.

Output:
what's your first name? amil
My name is limA

9. What do we mean by expression substitution?
a) Embedding the value of Ruby expression into a string using #{ }
b) Substituting string functions
c) Storing string value
d) None of the mentioned

View Answer

Answer: a [Reason:] Strings are displayed #{} sequence.

10. What is the output of the given code?

 x, y, z = 12, 36, 72
    puts "The value of x is #{ x }."
    puts "The sum of x and y is #{ x + y }."
    puts "The average was #{ (x + y + z)/3 }."

a) 12,48,40
b) Syntax error
c) The value of x is 12.
The sum of x and y is 48.
The average was 40.
d) None of the mentioned

View Answer

Answer: c [Reason:] x, y, z assigned the values 12, 36, 72 and then arithmetic operations performed on them.

Output:
   The value of x is 12.
   The sum of x and y is 48.
   The average was 40.

11. What does %{Learn ruby language} represents?
a) “Learn Ruby language”
b) “%{Learn Ruby language}”
c) ” Learn Ruby language ”
d) None of the mentioned

View Answer

Answer: a [Reason:] Anything written inside %{} is same as anything written inside “”.

12. What does %Q{ Learn ruby language } represents?
a) ” Learn Ruby language ”
b) “%{ Learn Ruby language }”
c) ” Learn Ruby language ”
d) None of the mentioned

View Answer

Answer: a [Reason:] Anything inside %Q{} is written inside “”.

13. What does %x!ls! represents?
a) Same as back tick command output `ls`
b) Same as ‘x’
c) Same as “xls”
d) None of the mentioned

View Answer

Answer: a [Reason:] It is same as back tick command output `ls`.

Synopsis and Project Report

You can buy synopsis and project from distpub.com. Just visit https://distpub.com/product-category/projects/ and buy your university/institute project from distpub.com