Java Reference
In-Depth Information
EX 3.3
Write a declaration for a
String
variable called
change
and ini-
tialize it to the characters stored in another
String
object called
original
with all
'e'
characters changed to
'j'
.
EX 3.4
What output is produced by the following code fragment?
String m1, m2, m3;
m1 = "Quest for the Holy Grail";
m2 = m1.toLowerCase();
m3 = m1 + " " + m2;
System.out.println (m3.replace('h', 'z'));
EX 3.5
What is the effect of the following import statement?
import
java.awt.*;
EX 3.6
Assuming that a
Random
object has been created called
generator
, what is the range of the result of each of the follow-
ing expressions?
a.
generator.nextInt(20)
b.
generator.nextInt(8) + 1
c.
generator.nextInt(45) + 10
d.
generator.nextInt(100) − 50
EX 3.7
Write code to declare and instantiate an object of the
Random
class (call the object reference variable
rand
). Then write a list
of expressions using the
nextInt
method that generates random
numbers in the following specified ranges, including the end-
points. Use the version of the
nextInt
method that accepts a
single integer parameter.
a. 0 to 10
b. 0 to 500
c. 1 to 10
d. 1 to 500
e. 25 to 50
f.
10 to 15
EX 3.8 Write an assignment statement that computes the square root of
the sum of
num1
and
num2
and assigns the result to
num3
.
EX 3.9 Write a single statement that computes and prints the absolute
value of
total
.
EX 3.10 Write code statements to create a
DecimalFormat
object that
will round a formatted value to four decimal places. Then write
a statement that uses that object to print the value of
result
,
properly formatted.
-
Search WWH ::
Custom Search