This
exercise reviews the flow of execution through a program with multiple methods.
Read the following code and answer the questions below.
public
class Buzz {
public static void baffle(String
blimp) {
System.out.println(blimp);
zippo("ping",
-5);
}
public static void zippo(String quince, int flag)
{
if (flag
< 0) {
System.out.println(quince
+ " zoop");
} else {
System.out.println("ik");
baffle(quince);
System.out.println("boo-wa-ha-ha");
}
}
public static void main(String[] args) {
zippo("rattle",
13);
}
}
- Write
the number 1 next to the first statement of
this program that will be executed. Be careful to distinguish things that are
statements from things that are not.
- Write
the number 2 next to the second statement, and so on until the end of the
program. If a statement is executed more than once, it might end up with more
than one number next to it.
- What
is the value of the parameter blimp when baffle
gets invoked?
- What
is the output of this program?
SOLUTION
1.
1 System.out.println("ik");
2.
2 System.out.println(blimp);
3 System.out.println(quince + " zoop");
4 System.out.println("boo-wa-ha-ha");
3.Value of parameter blimp when baffle gets invoked is rattle.
4.
ik
rattle
ping zoop
boo-wa-ha-ha