- Statement = a line of code that performs a basic operation
- Method = a named sequence of statements
-
Usage:
- to do non-simple operations repeatedly
- to break complex problems into smaller, simpler parts
Types of Methods
| VOID Method | VALUE Method |
|---|---|
| Does not return a value | Returns a value |
| Often referred to as a procedure | Often referred to as a function |
Void Method
Penjelasan
Penjelasan
- Method Names

- Parameters and Arguments

- Statements

- Overloading

Exercise Void Method
- Exercise 1
- Solution Exercise 1
Write one or several methods to do the following
- Prints a String n times
- Display the message “Good Morning” in various languages
- Display an alphanumeric character as an ASCII art
Value Method
Penjelasan
Penjelasan
- Return type and value


Exercise Value Method
- Exercise 1
- Solution Exercise 1
Write one or several methods to do the following
- Calculates the distance between two coordinates
- Determines whether a number is prime or not
- Determines the number of days in a year
Method Composition
Recursive Methods

https://keenformatics.blogspot.com/2013/08/how-to-solve-json-infinite-recursion.html
- A method that invokes itself
- example:
- Write the base case:
- Write the reduction step. Ensure that the base case can be reached:
Recursion vs Iteration
- Recursion is not always needed
- Everything that can be done with recursion can be done using iterations (loops)
- Recursion
- consumes more memory and slower than iterations
- elegant, shorter code
Documentation
- True
- False

