Java Reference
In-Depth Information
d.
str2.toUpperCase()
e.
str1.substring(2, 4)
f.
str2.substring(10, 14)
g.
str1.indexOf("D")
h.
str1.indexOf(".")
i.
str2.indexOf("donkey")
j.
str3.indexOf("X")
k.
str2 + str3.charAt(17)
l.
str3.substring(9, str3.indexOf("e"))
m.
str3.substring(7, 12)
n.
str2.toLowerCase().substring(9, 13) + str3.substring(18, str3.length() - 7)
15.
Consider the following
String
:
String quote = "Four score and seven years ago";
What expression produces the new
String "SCORE"
? What expression produces
"four years"
?
16.
In a program reading user input by means of a
Scanner
, the user types the following line of input:
Hello there. 1+2 is 3 and 1.5 squared is 2.25!
Into how many tokens will this line be split? What is each token?
17.
Consider the following code fragment:
Scanner console = new Scanner(System.in);
System.out.print("How much money do you have? ");
double money = console.nextDouble();
Describe what will happen when the user types each of the following values. If the code will run successfully, describe
the value that will be stored in the variable
money
.
a.
34.50
b.
6
c.
$25.00
d.
million
e.
100*5
f.
600,000
g.
none
h.
645
18.
Write Java code to read an integer from the user, then print that number multiplied by 2. You may assume that the user
types a valid integer.
19.
Write Java code that prompts the user for a phrase and a number of times to repeat it, then prints the phrase the
requested number of times. Here is an example dialogue with the user:
What is your phrase?
His name is Robert Paulson.
How many times should I repeat it?
3
His name is Robert Paulson.
His name is Robert Paulson.
His name is Robert Paulson.
Search WWH ::
Custom Search