Saturday, February 13, 2016

Exercise 4.2

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);
}
}

  1. 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.
  2. 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.
  3. What is the value of the parameter blimp when baffle gets invoked?
  4.  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


1 comment: