Bird
0
0

How can you use a Kotlin for loop with ranges to print the multiplication table of 3 from 3 to 30?

hard📝 Application Q9 of 15
Kotlin - Loops and Ranges
How can you use a Kotlin for loop with ranges to print the multiplication table of 3 from 3 to 30?
Afor (i in 3..30 step 3) { println(i) }
Bfor (i in 1..10) { println(i * 3) }
Cfor (i in 3..30) { if (i % 3 == 0) println(i) }
DAll of the above
Step-by-Step Solution
Solution:
  1. Step 1: Understand each approach

    for (i in 3..30 step 3) { println(i) } uses step 3 from 3 to 30, printing multiples of 3. for (i in 1..10) { println(i * 3) } multiplies loop variable by 3 from 1 to 10. for (i in 3..30) { if (i % 3 == 0) println(i) } checks multiples of 3 in 3 to 30.
  2. Step 2: Verify all print the multiplication table of 3

    All options print 3,6,9,...30 correctly.
  3. Final Answer:

    All of the above -> Option D
  4. Quick Check:

    Multiple ways to print multiplication table = B [OK]
Quick Trick: Use step, multiplication, or condition for tables [OK]
Common Mistakes:
MISTAKES
  • Using wrong step size
  • Looping incorrect range
  • Missing condition for multiples

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes