Bird
0
0

What will this Ruby code print?

medium📝 Predict Output Q5 of 15
Ruby - Arrays
What will this Ruby code print?
arr = ["a", "b", "c"]
arr[1] = "z"
puts arr.join
Aazc
Babc
Caz
Dzbc
Step-by-Step Solution
Solution:
  1. Step 1: Understand array element assignment

    arr[1] = "z" changes the second element from "b" to "z".
  2. Step 2: Join array elements into a string

    arr.join combines elements into "azc".
  3. Final Answer:

    azc -> Option A
  4. Quick Check:

    Element replaced and joined = azc [OK]
Quick Trick: Assign by index to change array elements [OK]
Common Mistakes:
MISTAKES
  • Confusing index positions
  • Expecting original array unchanged
  • Misunderstanding join output

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Ruby Quizzes