Professional Documents
Culture Documents
Chapter 7
User-Defined Methods
Chapter Objectives
• Understand how methods are used in Java
programming
• Learn about standard (predefined) methods
and discover how to use them in a program
• Learn about user-defined methods
• Examine value-returning methods,
including actual and formal parameters
• Method call
-The syntax to call a value-returning method is:
if (x >= y)
max = x;
else
max = y;
return max;
}
return y;
}
• Sample Run
Enter 10 numbers:
10.5 56.34 73.3 42 22 67 88.55 26 62 11
The largest number is 88.55
//block
{
double x; //illegal declaration,
//x is already declared
...
}
}
//block three
{
int x = 12;
//...
} //end block three
//...
}
}
Java Programming: From Problem Analysis to Program Design, 5e 62
Scope Rules: Demonstrated