ITE2 Methods
ITE2 Methods
CRISTY S. CARPON
COLLEGE OF COMPUTING AND INFORMATION SCIENCES
1
What is a method?
Often called as modules or function.
a block of code that performs a specific
‘-
task.
used to divide complicated programs into
manageable pieces.
can be used to define reusable code and
organize and simplify coding 2
Types of Java Methods
Predefined Methods
built-in methods in Java that are
‘-
readily available for use
User-defined Methods
Methods that created by the user.
3
Example of Predefined Methods
‘-
4
User-Defined Methods Categories
‘-
5
‘-
6
‘-
7
‘-
8
How to call a Java Method?
‘-
9
‘-
10
Example
‘-
11
‘-
12
‘-
13
Void Methods
‘-
14
‘-
15
‘-
16
‘-
17
Exercise
1. Write a program that will find the sum of three
numbers using methods.
2. Write a program that will compute the sum of the
‘-
sequence numbers from 1 to N where N is a
supplied value entered by the user.
3. Write a program that will ask the user to input two
numbers and then the program will swap or
interchange the arrangement of two numbers given
by the user. 18