Académique Documents
Professionnel Documents
Culture Documents
Code Reuse:
Methods in Java
CSE 110: Introduction to Computer Science
Stony Brook University
e.g., f(x) = x
Given the same input, it will always return
2
Calling Methods
To call a method, write its name, followed by
its arguments (if any) in parentheses:
System.out.print(Hello world!);
Math.pow(2, 3);
Defining a Method
Method Input/Output
arguments or parameters)
Return Values
If a method has a return type other than
A void Method
void printLineOfStars()
System.out.println(**********);
return statement!
// body