Aswers

Question 1: Basic try-catch Usage

Correct Answer: A) Cannot divide by zero.
Operation attempted.

Question 2: Catching Multiple Exceptions

Correct Answer: B) Array index out of bounds.
Search attempted.

Question 3: Using try-catch with a Return Value

Correct Answer: A) Division operation processed.
Error: Division by zero.
Division operation processed.
Result: 2

Question 4: Using Option for Safe Value Access

Correct Answer: A) Some(a)
None

Question 5: Handling Multiple Errors with Either

Correct Answer: A) Right(5)
Left("Cannot divide by zero.")

Question 6: Graceful Error Handling with Try

Correct Answer: A) Success(100)
Failure(java.lang.NumberFormatException)

Question 7: Combining Option Values with flatMap

Correct Answer: A) Some(5)
None

Question 8: Using for-comprehension with Option

Correct Answer: A) Some(30)

Question 9: Safely Accessing Potentially Null Objects

Correct Answer: A) JohnDoe
Unknown

Question 11: Pattern Matching with Options to Handle Nulls

Correct Answer: A) Found word: Scala
No word found

Question 12: Encapsulating Nullable References with Options

Correct Answer: A) 5
0

Question 13: Creating and Accessing a Map

Correct Answer: A) Some(Paris)
Not found

Question 14: Updating and Adding Elements to a Map

Correct Answer: C) Map(1 -> "one", 2 -> "TWO", 3 -> "three")

Question 15: Iterating Over a Map

Correct Answer: A) Alice is 30 years old
Bob is 25 years old
Charlie is 28 years old

Question 16: Using Options for Safe Access

Correct Answer: B) 10

Question 17: Handling Exceptions with Try and Match

Correct Answer: B) Error: / by zero

Question 18: Using flatMap to Flatten and Transform

Correct Answer: A) List(2, 4, 6, 8, 10, 12)

Question 19: Folding a List with foldLeft

Correct Answer: A) 15

Question 20: Basic Usage of zip

Correct Answer: A) List(("Alice", 25), ("Bob", 30), ("Charlie", 28))

Question 21: zip with Unequal Collection Sizes

Correct Answer: B) List((1, 'a'), (2, 'b'), (3, 'c'))

Question 22: Using zipWithIndex

Correct Answer: A) List(("apple", 0), ("banana", 1), ("cherry", 2))

Question 23: Basic Usage of groupBy

Correct Answer: B) Map(a -> List("apple", "apricot"), b -> List("banana"), p -> List("pear", "peach"))

Question 24: Higher-Order Functions

Correct Answer: B) 25

Question 25: Simple Recursive Function for Summation

Correct Answer: A) 55 and 15