June 2017
Beginner
1296 pages
69h 23m
English
[Note: This section may be read after studying Chapter 6, Methods: A Deeper Look, and the preceding portions of Chapter 25.]
You can use JShell to prototype methods. For example, let’s assume we’d like to write code that displays the cubes of the values from 1 through 10. For the purpose of this discussion, we’re going to define two methods:
Method displayCubes will iterate 10 times, calling method cube each time.
Method cube will receive one int value and return the cube of that value.
displayCubesLet’s begin with method displayCubes. Start a new JShell session or /reset the current one, then enter the following method declaration:
void displayCubes() ...