Question 1 of 10
A city name is clipped to a three-letter tag. What text does this Java code display?
String city = "denver";
System.out.print(city.substring(0, 3));
- A. den
- B. ver
- C. denv
- D. denver
A city name is clipped to a three-letter tag. What text does this Java code display?
String city = "denver";
System.out.print(city.substring(0, 3));
A spark code prints one interior character and the last character. What text does this Java code display?
String code = "spark";
System.out.print(code.charAt(1));
System.out.print(code.charAt(code.length() - 1));
How many letters p are in pepper? What text does this Java code display?
String s = "pepper";
int i = 0;
int p = 0;
while (i < s.length()) {
if (s.substring(i, i + 1).equals("p")) {
p++;
}
i++;
}
System.out.print(p);
A short word is reversed with a while loop. What text does this Java code display?
String s = "rid";
String rev = "";
int i = s.length() - 1;
while (i >= 0) {
rev += s.charAt(i);
i--;
}
System.out.print(rev);
A garden word is searched, then a four-letter slice from that index is printed. What text does this Java code display?
String s = "sunflower";
int at = s.indexOf("flow");
System.out.print(at);
System.out.print(s.substring(at, at + 4));
Overlapping two-letter windows of thatthat are compared with th. What text does this Java code display?
String s = "thatthat";
int count = 0;
for (int i = 0; i <= s.length() - 2; i++) {
if (s.substring(i, i + 2).equals("th")) {
count++;
}
}
System.out.print(count);
Two produce labels are compared. What text does this Java code display?
String x = "pea";
String y = "pear";
if (x.compareTo(y) < 0) {
System.out.print("first");
} else {
System.out.print("second");
}
A word is reversed and then compared with the original. What text does this Java code display?
String s = "noon";
String rev = "";
for (int i = s.length() - 1; i >= 0; i--) {
rev += s.substring(i, i + 1);
}
if (s.equals(rev)) {
System.out.print("mirror");
} else {
System.out.print("plain");
}
After the first c in abracadabra, remaining a characters are counted. What text does this Java code display?
String s = "abracadabra";
int start = s.indexOf("c");
int count = 0;
for (int i = start; i < s.length(); i++) {
if (s.charAt(i) == 'a') {
count++;
}
}
System.out.print(count);
A clipped piece of quartz is measured. What text does this Java code display?
String s = "quartz";
String mid = s.substring(1, 5);
System.out.print(mid.length());