Methods like variables
In the last lesson, we went over void methods. These are methods that do not return a value.
Returning a value means that we can use methods like variables or even values, making calculations very easy to do.
We follow the same steps as creating a method, except we change two things:
- Instead of
void, we use a data type or object. We want the method to know what kind of value/variable it is returning - We also add
returninside of the method, to choose what exactly is returned.
Let's try it with this example:
Java
public static void