Question:

What output will be produced by the code below?

import Foundation
let rounded: Int = round(10.5)
print("Rounding 10.5 makes \(rounded)")

Correct answer: This code will not compile.

Explanation: The round() method accepts a Double and returns a Double, or accepts a Float and returns a Float. This code creates rounded as an integer then tries to force the result of round() into it, which is not allowed without a typecast.


Keywords:

© 2017 QuizBucket.org