Java Reference
In-Depth Information
6 }
7
8 public static void drawTriangle() {
9 System.out.println(" *");
10 System.out.println(" ***");
11 System.out.println("*****");
12 System.out.println();
13 }
14
15 public static void drawTwoTriangles() {
16 drawTriangle();
17 drawTriangle();
18 }
19 }
The program prints three triangles:
*
***
*****
*
***
*****
*
***
*****
How do we describe the method calls that take place in this program? Imagine that
each method call has been written on a different piece of paper. We begin program
execution with the main method, so imagine that we're grabbing the sheet of paper
with main on it:
public static void main(String[] args) {
drawTriangle();
drawTwoTriangles();
}
We then execute each of the statements in main in turn, from first to last. First we
execute the call on drawTriangle :
public static void main(String[] args) {
drawTriangle();
drawTwoTriangles();
}
Search WWH ::




Custom Search