Hi all,
I have been doing the youtube videos for cs106a to try and learn to use java. I am however struggling with this one question:
For the program below, trace through its execution by hand to show what output is
produced when it runs
I can pretty much follow most of the question apart from this part here:
More specifically the snitch(x+y, y); I know the x+y part but im not sure what the , y part means or how I find its value.
Is it that I have to do the snitch method, and where it says return y, I return that value to the function where it was called (which is the int z = snitch (x+y ,y) <-- this second y?
Hope I explained that well enough to help me out!
Thanks
I have been doing the youtube videos for cs106a to try and learn to use java. I am however struggling with this one question:
For the program below, trace through its execution by hand to show what output is
produced when it runs
Code:
/*
* 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;
}
}
I can pretty much follow most of the question apart from this part here:
Code:
int z = snitch(x + y, y);
More specifically the snitch(x+y, y); I know the x+y part but im not sure what the , y part means or how I find its value.
Is it that I have to do the snitch method, and where it says return y, I return that value to the function where it was called (which is the int z = snitch (x+y ,y) <-- this second y?
Hope I explained that well enough to help me out!
Thanks