need help in AP Computer Science!
So basically, I'm a sophemore in highschool taking APCS and I'm having some trouble with my homework. Any help would be greatly appreciated. Soo what are the outputs for each of the statements in this code:
public class MysteryReturn {
public static void main(String[] args) {
int x = 1;
int y = 2;
int z = 3;
z = mystery(x, z, y); // Statement 1
System.out.println(x + " " + y + " " + z); // Statement 2
x = mystery(z, z, x); // Statement 3
System.out.println(x + " " + y + " " + z); // Statement 4
y = mystery(y, y, z); // Statement 5
System.out.println(x + " " + y + " " + z); // Statement 6
}
public static int mystery(int z, int x, int y) {
z--;
x = 2 * y + z;
y = x - 1;
System.out.println(y + " " + z);
return x;
}
}
Re: need help in AP Computer Science!
Quote:
what are the outputs for each of the statements
Do you have the javac and the java commands? If not you need to download the JDK and install it.
Then you will be able to compile with javac and execute the program with java and see what those statements output.
Re: need help in AP Computer Science!
the outputs are:
3 0
1 2 4
4 3
5 2 4
8 1
5 9 4
Re: need help in AP Computer Science!
Are those outputs correct? Is your question answered?