Functions and Conditionals

Functions and Conditionals

TOTAL POINTS 3
1.Question 1
Consider the following Java methods.
1
2
3
4
5
6
7
8
9
10
11
12
13
int func2(int w) {
return w * 3;
}
int func1 (int a, int b) {
int n = a + b;
return 2 + func2(n);
}
int start() {
int z = 4;
return func1(z, 1) - 3;
}
What is the return value of the call start()?
1 point
2.Question 2
Consider the following method g.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int g (int a) {
if (a < 9) {
return 9;
}
if (a < 7) {
return 7;
}
if (a < 4) {
return 4;
}
return 0;
}
What is the value returned from the call g(5)?
1 point
3.Question 3
Consider the following method k.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
int k (int a, int b) {
if (a < b) {
if (b > 4) {
return 0 ;
}
else {
return 1;
}
}
else {
if (a > 4) {
return 2;
}
else {
return 3;
}
}
}
For which of the values a and b would 2 be the return value?
1 point

تعليقات