Question 1 of 10
A label is clipped from a planet name. What text does this Java code display?
String word = "planet";
System.out.print(word.substring(1, 4));
- A. lan
- B. pla
- C. lane
- D. plan
A label is clipped from a planet name. What text does this Java code display?
String word = "planet";
System.out.print(word.substring(1, 4));
A comet tag is shortened, then its original length is printed. What text does this Java code display?
String tag = "comet";
System.out.print(tag.substring(2));
System.out.print(tag.length());
How many times does the letter a appear in banana? What text does this Java code display?
String s = "banana";
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'a') {
count++;
}
}
System.out.print(count);
Overlapping two-letter windows of aaaa are compared with aa. What text does this Java code display?
String s = "aaaa";
int count = 0;
for (int i = 0; i < s.length() - 1; i++) {
if (s.substring(i, i + 2).equals("aa")) {
count++;
}
}
System.out.print(count);
A tree name is rebuilt from last character to first. What text does this Java code display?
String s = "oak";
String rev = "";
for (int i = s.length() - 1; i >= 0; i--) {
rev += s.substring(i, i + 1);
}
System.out.print(rev);
A search reports where te occurs in notebook, then where z occurs. What text does this Java code display?
String title = "notebook";
System.out.print(title.indexOf("te"));
System.out.print(" ");
System.out.print(title.indexOf("z"));
Two kite-shop labels are compared. What text does this Java code display?
String a = "kite";
String b = "kit";
if (a.compareTo(b) > 0) {
System.out.print("after");
} else {
System.out.print("not after");
}
A word is reversed by prepending one character at a time, then a slice is printed. What text does this Java code display?
String s = "trace";
String rev = "";
int i = 0;
while (i < s.length()) {
rev = s.substring(i, i + 1) + rev;
i++;
}
System.out.print(rev.substring(1, 4));
Vowels in audio are counted by asking whether each one-character piece appears in aeiou. What text does this Java code display?
String s = "audio";
int count = 0;
for (int i = 0; i < s.length(); i++) {
String ch = s.substring(i, i + 1);
if ("aeiou".indexOf(ch) >= 0) {
count++;
}
}
System.out.print(count);
A maple tag is tested with equals after a prefix clip. What text does this Java code display?
String s = "maple";
if (s.substring(0, 3).equals("map")) {
System.out.print("yes");
} else {
System.out.print("no");
}