functions (methods)
TRANSCRIPT
Functions (Methods)
Rajath RIX A
Functions (Methods)What is a function ?
A function is a set of statements that is used to perform a specific task simultaneously at different instances in a program.
Why is it advantageous to use functions ? There are three main reasons why we use functions
in a program, which are : To allow us to cope with complex computational tasks into
a collection of smaller methods so that problem solving becomes easier.
To hide low-level inner code details that otherwise seem obscure and confuse the end-user.
To re-use portions of code as and when necessary by simply using the method names.
Functions (Methods)How do you define a function ?
A function is defined using the syntax given below. Syntax :<access specifier> <return data type> <function name>
( <parameter list> ){
// block of statements ;return <return value>;
}Give an example of a function.
public double simpleinterest ( int p, int t, int r ){
double sim = ( p * t * r ) / 100 ;return sim ;
}
Body of the function
]
Functions (Methods)What are the components of a function ?
A function has the following components :