___1.
What is the value of position after the following
statement executes?
int
position = "string".indexOf("tri", 3);
a) -1
b) 1
c) 2
d) 3
___2. What is the value of
str after the
following statement executes?
String
str = "faLL".toLowerCase();
a) FALL
b) Fall
c) fall
d) FaLL
___3.
What is the value of str after the
following statement executes?
String
str = "string".substring(0, 3);
a) str
b) ing
c) rin
d) stringstringstring
___4. What is
the value of str after the
following statement executes?
String
str = "string".substring(1, 4);
a) str
b) stri
c) tri
d) trin
___5. What is
the value of chars after the
following statement executes?
int
chars = "string".length();
a) 0
b) 1
c) 5
d) 6
___6. What is
the value of str after the
following statement executes?
String
str = "string".substring(3);
a) ing
b) str
c) i
d) stringstringstring
___7.
What is the value of comp after the
following statement executes?
int
comp = "Fall".compareToIgnoreCase("fall");
a) 0
b) a negative integer
c) a positive integer
d) false
8) Fill in the blanks
following this example:
Random generator = new Random();
generator.nextDouble()
// generates a
random double from 0 to 1
a) generator.nextDouble() * 90 + 10 //
generates a
random from
to
b) generator.nextInt(3) // generates a
random
from
to
c) generator.nextInt(11) - 5 // generates
a
random
from
to
d) generator.nextDouble() + 5 ' generates
a random from
to
___9.
What is the value of str after the
following statement executes?
String
str = "LEttERs".toUpperCase();
a) LETTERS
b) Letters
c) letters
d) lEttERs
Questions 10 through 15 refer to the following code:
System.out.print("What's the good
word my friend? ");
String str = Stdin.readLine();
char a = str.charAt(0);
int count = 0;
String b =
str.substring(str.length() - 3);
char c = str.charAt(2);
String d = str.substring(1, 2);
if (Character.isUpperCase( )) {
System.out.println(str + " is a proper noun.");
count++;
}
if ( .equals("ing")) {
System.out.println(str + " is a gerund.");
count++;
}
if ( == 'r')
count++;
int ord = .compareTo("p");
if (ord > 0)
count++;
else if (ord < 0)
System.out.println("Getting cold.");
else
System.out.println("Getting warm.");
if (count == 4)
System.out.println(str + " is the secret word.");
10) Assuming "String" is the secret word, match the
variables a, b, c, and d with the blanks in the code.
What is the output if the user enters:
11) "spring"
12) "Sing"
13) "Sling"
14) "store"
15) "or"