{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

11-methods - Code Reuse Methods in Java CSE 110...

Info icon This preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Code Reuse: Methods in Java CSE 110: Introduction to Computer Science SUNY at Stony Brook
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Methods A method is a block of code that can be reused within a program It’s like a mini-program inside the main program Use methods to break up a task into smaller parts This is especially useful if you need to repeat an operation with different data
Image of page 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); The order of arguments is important! When a method is called, the code that called it is put on hold while the method executes
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Method Input/Output A method can take input values (called arguments or parameters ) The method uses these values in its work A method can also return a value It can send back the result of its calculation to the main program Input and output are optional for methods
Image of page 4
Methods are Functions
Image of page 5

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}