|
2.
|
Suppose the method int sign(int x) returns 1 if x is positive, -1 if x is negative and 0 if x is 0. Given int[] nums = {-2, -1, 0, 1, 2};
what are the values of
the elements of nums after the following code is executed? for(int k=0; k<nums.length; k++) {
nums[k] -=
sign(nums[k]); nums[k] += sign(nums[k]);
}
a. | -2, -1, 0, 1, 2 | b. | -1, 0, 0, 0, 1 | c. | 0, 0, 0, 0,
0 | d. | -2, 0, 0, 2, 3 | e. | -2, 0, 0, 0, 2 |
|
|
5.
|
Consider the following method:
public static
String process(String msg, String s) { int pos =
msg.indexOf(s); msg = msg.substring(0,pos) + " " +
s; return msg; }
What is the output of the
following code segment?
String s1 = "superstar"; String s2 =
"star"; System.out.println(process(s1, s2));
a. | superstar | b. | superstarstar | c. | super
star | d. | superstar star | e. | super starstar |
|