{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

20-section-handout-3

20-section-handout-3 - Mehran Sahami CS 106A Handout#20...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Mehran Sahami Handout #20 CS 106A October 15, 2007 Section Handout #3 Parameters, Random Numbers, and Simple Graphics Portions of this handout by Eric Roberts and Patrick Young. 1. True/False questions For each of the following statements below, indicate whether it is true or false in Java: a) The value of a local variable named i has no direct relationship with that of a variable named i in its caller. b) The value of a parameter named x has no direct relationship with that of a variable named x in its caller. 2. Tracing method execution For the program below, trace through its execution by hand to show what output is produced when it runs. /* * File: Hogwarts.java * ------------------- * This program is just testing your understanding of parameter passing. */ import acm.program.*; public class Hogwarts extends ConsoleProgram { public void run() { bludger(2001); } private void bludger(int y) { int x = y / 1000; int z = (x + y); x = quaffle(z, y); println("bludger: x = " + x + ", y = " + y + ", z = " + z); } private int quaffle(int x, int y) { int z = snitch(x + y, y); y /= z; println("quaffle: x = " + x + ", y = " + y + ", z = " + z); return z; } private int snitch(int x, int y) { y = x / (x % 10); println("snitch: x = " + x + ", y = " + y); return y; } }
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}