Using the following method, what are the values of the following expressions?
public static int f(int x) {
int y = 4 * x;
if(y < 10) return y;
y++;
return y / 6;
}
| a. | 15 - 1 - 3 * 2 |
|---|---|
| b. | 15 - 12 % 5 |
| c. | f(1) |
| d. | f(f(4)) |
Consider the following method to compute the greatest common denominator of two numbers.
public static int gcd(int m, int n) {
int r;
while(m != 0) {
r = m % n;
m = n;
n = r;
}
return m;
}
r m 42 n 54
Fill in run() so that the method will print ``Hello'' to the screen 2,001 times.
import csbsju.cs160.*;
public class PrintHello {
public static void run() {
}
}
Say we've defined the following method.
public static int f(int x) {
IO.print(x);
return x * 2;
}
| a. | 8 |
|---|---|
| b. | 13 |
| c. | 4 |
| d. | 8 |
r 42 12 6 0 m 42 54 42 12 6 n 54 42 12 6 0
import csbsju.cs160.*;
public class PrintHello {
public static void run() {
int i = 0;
while(i < 2001) {
IO.println("Hello");
i++;
}
}
}