-
- true
- false
- 0, 1, or 2
- true
- 22 11 5 2 1 0
- "Xabc"
-
-
import java.util.Vector
-
java.util.Vector()
-
java.util.Vector() or Vector()
-
if (x < 0.0)
y = 0.0;
else
y = Math.sqrt(x);
- The problem is that the "else" will be interpreted as matching the nearest "if" -- which is the second "if" and not the first one as desired. The code may be fixed by introducing braces:
if (isPasswordCorrect()) {
if (balance < amount)
handleInsufficientBalance(); }
else
handleIncorrectPassword();
- One way:
public void deductServiceCharge() {
if (balance < SERVICE_CHARGE_THRESHOLD)
balance = balance - SERVICE_CHARGE; }
- One way:
public static String starify(String s) {
String output = "";
for (int i=0; i<s.length(); i++) {
char c = s.charAt(i);
if (isVowel(c))
output = output + "*";
else
output = output + c; }
return output; }
- Because almost certainly the test that is wanted is whether the two strings are spelled the same (which is what the
equals method tests), rather than whether the two strings are identical (which is what the == operator tests).