Slide 53
Slide 53 text
/* First we must define a method */
int addTwoIntegers(int a, int b)
{
return a + b;
}
/* Then we use the method */
addTwoIntegers(10,15); /* 25! */
/* We can treat a method like it is a variable of its
return type */
int x = addTwoIntegers(10, 15); /* x is 25 */
int y = addTwoIntegers(2,6) + addTwoIntegers(8,12);
/* y is 28 */
Programming Flow
• Jumps/”Methods” or “Functions”
15
Wednesday, June 27, 12
- The return type is the type of the value that the method spits out.
- The method name is what you use to “call” the method
- The arguments describe what the method needs to work
- The method body can be as long as you want, and contains all of the instructions that the
method should carry out. This can include the other methods, loops, ifs, etc.
- The return value is the value that the method spits back out once it has completed its
instructions