NAME |
___________________________
|
Perm. no. | _________________ |
Question | Value | Score |
1 | 20 | |
2 | 20 | |
3 | 20 | |
4 | 20 | |
5 | 20 | |
Total | 100 |
1. Let a and b be int variables. Translate the following nested if/else statement to an equivalent switch statement. If this cannot be done, explain why.
boolean composite(int n) { return !prime(n); }
for
(int i = 0; i < a.length && i < b.length && i <
c.length; i++)
c[i] = a[i] + b[i];
}
for (int i = 0; i <
a.length; i++)
a[i] = i;
for (int i = 0; i <
b.length; i++)
b[i] = (int) (21*Math.random()) - 10;