Java Reference
In-Depth Information
Notice the if statement. If i is zero, then the outcome of the if is false, the division by zero
is prevented, and no result is displayed. Otherwise, the division takes place.
Chapter 5 Self Test
1 . Show two ways to declare a one-dimensional array of 12 double s.
2 . Show how to initialize a one-dimensional array of integers to the values 1 through 5.
3 . Write a program that uses an array to find the average of 10 double values. Use any
10 values you like.
4 . Change the sort in Try This 5-1 so that it sorts an array of strings. Demonstrate that it
works.
5 . What is the difference between the String methods indexOf( ) and lastIndexOf( ) ?
6 . Since all strings are objects of type String , show how you can call the length( ) and
charAt( ) methods on this string literal: "I like Java".
7 . Expanding on the Encode cipher class, modify it so that it uses an eight-character
string as the key.
8 . Can the bitwise operators be applied to the double type?
9 . Show how this sequence can be rewritten using the ? operator.
10 . In the following fragment, is the & a bitwise or logical operator? Why?
11 . Is it an error to overrun the end of an array? Is it an error to index an array with a neg-
ative value?
12 . What is the unsigned right-shift operator?
13 . Rewrite the MinMax class shown earlier in this chapter so that it uses a for-each style
for loop.
Search WWH ::




Custom Search