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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Code Reuse: Methods in Java CSE 110: Introduction to Computer Science SUNY at Stony Brook Methods A method is a block of code that can be reused within a program Its 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 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 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 Methods are Functions A function maps (translates) some input value...
View Full Document

This note was uploaded on 03/29/2012 for the course CSE 110 taught by Professor Shaunakpawagi during the Spring '08 term at SUNY Stony Brook.

Page1 / 12

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

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online