Computer Science : Double

Study concepts, example questions & explanations for Computer Science

varsity tutors app store varsity tutors android store

Example Questions

Example Question #22 : Primitive Data Types

How do we declare a method to return a Double in Swift (iOS)?

Possible Answers:

func -> Double {}

func method() -> Double {}

func method -> Double {}

method() -> Double {}

Correct answer:

func method() -> Double {}

Explanation:

In Swift, all methods must first say what they are. They are functions, so they are prefixed with func. Next, methods must have a name. In this case, we named it method. All methods need to specify parameters, even if there are no parameters. So, method() i.e. no parameters. Finally, we wanted to return a Double. So we set the return type using -> Double. 

Learning Tools by Varsity Tutors