Olete.in
Articles
Mock Tests
๐งช Ruby MCQ Quiz Hub
Ruby Multiple Choice Questions Set 2
Choose a topic to test your knowledge and improve your Ruby skills
1. What is the output of the given code? i = 0 while i < 5 puts i i=(i+1)**2 end
1 2 3 4 5
0 1 4
0 1
1 4
2. What is the output of the given code? a=5 b=15 while a&&b puts a+b end
5..15
20
Infinite loop
5 15
3. What is the output of the given code? a=5 b=15 while b>a puts a*(b-a) while a>b a+=1 b-=1 end end
5..15
50
Infinite loop
5 50
4. What is the output of the given code? i = 3 while i > 0 do print i i -= 1 end
3
321
Infinite loop
3 2 1 0
5. What is the output of the given code? i = 50 while i > 25 do print 50/i i -= 1 end
50..25
50..1
Infinite loop
1111111111111111111111111
6. What is the output of the given code? a = 5 b=10 while a<b do puts a*b a+=2 b-=2 end
5 10
50 56
Infinite loop
5 6 7 8 9 10
7. What is the output of the given code? i = 50 j=55 while i > 25 && j>35 do puts 50*j/i i -= 1 j-=2 end
25 35
50 55
Infinite loop
55 54 53 52 51 50 48 47 46 45
8. What is the output of the given code? i = 50 j=55 while i > 25 && i*j<100 do puts (50*j)/i i -= 1 j-=2 end
25 35
No output
Infinite loop
55 54 53 52 51 50 48 47 46 45
9. What is the output of the given code? counter = 1 until counter > 10 puts counter counter+=1 end
1 2 3 4 5 6 7 8 9 10
11 12 13 14 โฆ infinite loop
0 1 2 3 4 5 6 7 8 9
None of the mentioned
10. What is the output of the given code? for num in 1...5 puts num end
1 2 3 4 5
1 2 3 4
2 3 4 5
None of the mentioned
11. What will be the output of the following? array = [100, 200, 300, 400, 500] print array[4]
400
500
Nil
None of the mentioned
12. What will be the output of the following? array = [100, 200, 300, 400, 500] print array[5]
400
500
Nil
None of the mentioned
13. What will be the output of the following? array = [100, 200, 300, 400, 500] print "array[5]"
array[5].
500
Nil
None of the mentioned
14. What will be the output of the following? array1 = [100, 200, 300, 400, 500] array2 = [1,2,3,4,5] if array1 == array2 print "They are equal" else print "Not equal" end
They are equal
Not equal
Nil
None of the mentioned
15. What will be the output of the following? array1 = [0,0,0] array2 = [0,0,0] if array1 == array2 print "They are equal" else print "Not equal" end
They are equal
NilNot equal
Nil
None of the mentioned
16. What will be the output of the following? array1 = [1,2,3] array2 = [0,0,0] if array1 == array2 print "Equal" else print "Not equal" end
Equal
Not equal
Error
None of the mentioned
17. What is the output of the given code? string_array = ["a","e","i","o","u"] print string_array
[โaโ,โeโ,โiโ,โoโ,โuโ].
Error
Vowels
None of the mentioned
18. What is the output of the given code? string_array = ["a","e","i","o","u"] print string_array[3]
[โaโ,โeโ,โiโ,โoโ,โuโ].
Error
o
None of the mentioned
19. What is the output of the given code? string_array = ["a","e","i","o","u"] boolean_array = ["True","False"] puts string_array[3] puts boolean_array
[โaโ,โeโ,โiโ,โoโ,โuโ].
Error
o True False
None of the mentioned
20. What is the output of the given code? string_array = ["a","e","i","o","u"] boolean_array = ["True","False"] puts string_array[3] puts boolean_array[1]
[โaโ,โeโ,โiโ,โoโ,โuโ].
Error
o False
None of the mentioned
21. What is the output of the given code? a=[1,2,3,4,5] b=[1,2,4,6,8] if a[3]==b[2] print "Equal" end
Equal
Error
4
None of the mentioned
22. What is the output of the given code? a=[1,2,3,4,5] b=[1,2,3,4,5] if a==b print "Equal" else print "Not equal" end
Equal
Error
Not equal
None of the mentioned
23. What is the output of the given code? a=["hey", "ruby", "language"] b=["hey", "ruby", "language"] if a==b print "Equal" else print "Not equal" end
Equal
Error
Not equal
None of the mentioned
24. What is the output of the given code? a=["hey", "ruby", "language"] b=["hey", "language", "ruby"] if a==b print "Equal" else print "Not equal" end
Equal
Error
Not equal
None of the mentioned
25. What is the output of the given code? a=["hey", "ruby", "language"] b=[1, 2, 3] puts b[1] puts a[2]
3 ruby
b) Error c)
2 language
None of the mentioned
26. What is the output of the given code? multi_d_array = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]] print multi_d_array
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]].
[0, 0, 0, 0].
[0, 0, 0, 0][0, 0, 0, 0].
None of the mentioned
27. What is the output of the given code? array1 = [[1,2,3,4],[0,0,0,0]] array2 = [[1,2,3],[0,0,0,0]] if array1==array2 print "Equal" else print "Not equal" end
[[1, 2, 3, 4], [0, 0, 0, 0]].
Equal
Not equal
None of the mentioned
28. What is the output of the given code? array1 = [[1,2,3,4],[0,0,0,0]] array2 = [[1,2,3,4],[0,0,0,0]] if array1==array2 print "Equal" else print "Not equal" end
[[1, 2, 3, 4], [0, 0, 0, 0]].
Equal
Not equal
None of the mentioned
29. What is the output of the given code? array1 = [[1,2,3,4],[0,0,0,0]] array2 = [[1,2,3,4],[0,0,0,0]] print array1+array2
[[1, 2, 3, 4], [0, 0, 0, 0]].
[[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]].
[[2,4,6,8],[0,0,0,0]].
None of the mentioned
30. What is the output of the given code? array1 = [[1,2,3,4],[0,0,0,0]] array2 = [[1,2,3,4],[0,0,0,0]] print array1-array2
[[1, 2, 3, 4], [0, 0, 0, 0]].
[[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]].
[].
None of the mentioned
31. What is the output of the given code? array1 = [[1,2,3,4],[0,0,0,0]] array2 = [[1,2,3,4],[0,0,0,0]] print array1*array2
[[1, 2, 3, 4], [0, 0, 0, 0]].
[[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]].
[].
Error
32. What is the output of the given code? array1 = [[1,2,3,4],[0,0,0,0]] array2 = [[1,2,3],[0,0,0]] print array1 && array2
[[1, 2, 3], [0, 0, 0]].
[[1, 2, 3, 4], [0, 0, 0, 0], [1, 2, 3, 4], [0, 0, 0, 0]].
[].
Error
33. What is the output of the given code? array1 = [[1,2,3,4,5],[0,0,0,0]] array2 = [[1,2,3],[0,0,0]] print array1 || array2
[[1, 2, 3], [0, 0, 0]].
[[1, 2, 3, 4, 5], [0, 0, 0, 0]].
[].
Error
34. What is the output of the given code? array1 = [[1,2,3,4,5],[0,0,0,0]] array2 = [[1,2,3],[0,0,0]] print !array1
[[1, 2, 3], [0, 0, 0]].
[[1, 2, 3, 4, 5], [0, 0, 0, 0]].
False
Error
35. What is the output of the given code? a=[["a","b"]] b=[["e","a"]] print a + b
[[โaโ, โbโ], [โeโ, โaโ]].
[[โ2aโ, โbโ], [โeโ]].
False
Error
36. What is the output of the given code? string_array = ["a","e","i","o","u"] print string_array
โaโ,โeโ,โiโ,โoโ,โuโ].
Error
Vowels
None of the mentioned
37. What is the output of the given code? a=[1,2,3,4,5] b=[1,2,4,6,8] if a[3]==b[2] print "Equal" end
[โaโ,โeโ,โiโ,โoโ,โuโ]. b) c)
Error
o False
None of the mentioned
Submit