Home / Programming Questions / Ruby MCQs / Page 10

Ruby MCQs with answers Page - 10

Dear candidates you will find MCQ questions of Ruby here. Learn these questions and prepare yourself for coming examinations and interviews. You can check the right answer of any question by clicking on any option or by clicking view answer button.
Share your questions by clicking Add Question

Q. What will be the output of the given code?

Code:
for num in 1...4

   puts num*num

end
(A) 0 1 4 9
(B) 1 4 9 16
(C) 0 1 2 3
(D) 1 2 3

Q. What will be the output of the given code?

Code:
i=1
for i in 6..10
puts i**2
end
(A) 36 49 64 81
(B) 49 64 81 100
(C) 49 64 81
(D) 36 49 64 81 100

Q. What will be the output of the given code?

Code:
for i in 1..5 && j in 5..10
puts i+j
end
(A) 6 8 10 12 14 16
(B) Syntax Error
(C) 6 8 10 12 14
(D) Type Error

Q. What will be the output of the given code?

Code:
counter = 1
while counter < 5
  puts counter
  counter = counter + 1
end
(A) Prints the number from 1 to 4
(B) Prints the number from 1 to 5
(C) Prints the number from 2 to 5
(D) Prints the number from 2 to 4

Q. What will be the output of the given code?

Code:
counter = true
while counter !=false
  puts counter
end
(A) TRUE
(B) FALSE
(C) Syntax Error
(D) Infinite Loop

Q. What will be the output of the given code?

Code:
while a&&b
puts a
end
(A) TRUE
(B) FALSE
(C) Syntax Error
(D) Name Error

Q. What will be the output of the given code?

Code:
a=1
b=1
while a&&b
puts a+b
end
(A) 2
(B) 2 2 2 2 2
(C) Infinite Loop
(D) Syntax Error

Q. What will be the output of the given code?

Code:
i = 4
while i > 0 do
  print i
  i -= 1
end
(A) 321
(B) 3210
(C) 4321
(D) 43210

Login

Forgot username? click here

Forgot password? Click here

Don't have account? Register here.