Java Reference
In-Depth Information
173
΢΢Exercise R4.11. True or false? ( x is an int and s is a String )
a. Integer.parseInt(ÐÑ + x) is the same as x
b. ÐÑ + Integer.parseInt(s) is the same as s
c. s.substring(0, s.length()) is the same as s
΢΢Exercise R4.12. How do you get the first character of a string? The last
character? How do you remove the first character? The last character?
΢΢΢Exercise R4.13. How do you get the last digit of an integer? The first
digit? That is, if n is 23456 , how do you find out that the first digit is 2
and the last digit is 6 ? Do not convert the number to a string. Hint: %,
Math.log .
΢΢Exercise R4.14. This chapter contains several recommendations regarding
variables and constants that make programs easier to read and maintain.
Summarize these recommendations.
΢΢΢Exercise R4.15. What is a final variable? Can you define a final
variable without supplying its value? (Try it out.)
΢ Exercise R4.16. What are the values of the following expressions? In each
line, assume that
double x = 2.5;
double y = -1.5;
int m = 18;
int n = 4;
String s = "Hello";
String t = "World";
a. x + n * y - (x + n) * y
b. m / n + m % n
c. 5 * x - n / 5
d. Math.sqrt(Math.sqrt(n))
e. (int) Math.round(x)
Search WWH ::




Custom Search