# Void Return Type Methods and Mathematical Functions

posted 3 years ago

- 0

While preparing for an upcoming Coursera course (Introduction to Algorithms) I came across this statement in the text

Bold mine.

The part in bold stumped me. Can someone walk me through that statement?

For example, the main() static method in our programs has a void return type

because its purpose is to produce output.Technically, void methods do not(and neither does Math.random(), which

implement mathematical functions

takes no arguments but does produce a return value).

-- p. 24 Algorithms (4e), Sedgewick & Wayne

Bold mine.

The part in bold stumped me. Can someone walk me through that statement?

posted 3 years ago

- 1

The strict interpretation of a function is that basically, you give it some input (like 90 degrees), and you get some new value out - like 1. For any given input, there is exactly one possible output.

Since a method of type void does not give you back a return value, it does not fit the definition of a mathematical function.

Since a method of type void does not give you back a return value, it does not fit the definition of a mathematical function.

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors

Mike Simmons

Ranch Hand

Posts: 3028

10

I agree. Here's the link: http://aspose.com/file-tools |