Question
Exercise 6 This exercise reviews the flow of execution through a program with multiple methods. Read the following code and answer the questions. public class
Exercise 6
This exercise reviews the flow of execution through a program
with multiple methods. Read the following code and answer the questions.
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 line of code in this program that
will execute.
2. Write the number 2 next to the second line of code, and so on until the
end of the program. If a line 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?
Exercise 2
For the following program:
1. Draw a stack diagram that shows the state of the program the second
time ping is invoked.
2. What is the complete output?
public static void zoop(String fred, int bob) {
System.out.println(fred);
if (bob == 5) {
ping("not ");
} else {
System.out.println("!");
}
}
public static void main(String[] args) {
int bizz = 5;
int buzz = 2;
zoop("just for", bizz);
clink(2 * buzz);
}
public static void clink(int fork) {
System.out.print("It's ");
zoop("breakfast ", fork);
}
public static void ping(String strangStrung) {
System.out.println("any " + strangStrung + "more ");
}
Exercise 3
Draw a stack diagram that shows the state of the program in
Section 5.8 after main invokes nLines with the parameter n == 4, just before
the last invocation of nLines returns.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started