Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public static int secret(int x) { int i , j i = 2 * x; if (i > 10) j = x / 2; el

ID: 3634703 • Letter: P

Question

public static int secret(int x)
{
int i , j
i = 2 * x;
if (i > 10)
j = x / 2;
else
j = x / 3;
return j;
}
public static int another(int a, int b)
{
int j;
j = 0;
for (int i = a; i <= b; i++)
j = j + i;
return j;
}
What is the output of each of the following segments?
a) x = 10;
System.out.println(secret(x));
b) x = 5; y = 8;
System.out.println(another(x, y));
c) x = 10; k = secret(x);
System.out.println(x + " " + k + " " + another(x , k));
d) x = 5; y = 8;
System.out.println(another(x, y));

Explanation / Answer

What is the output of each of the following segments?
a) x = 10;
System.out.println(secret(x));

5


b) x = 5; y = 8;
System.out.println(another(x, y));

26


c) x = 10; k = secret(x);
System.out.println(x + " " + k + " " + another(x , k));


d) x = 5; y = 8;
System.out.println(another(x, y));

26