Object Methods vs Class (Static) Methods (API) Created by: Barb Ericson

advertisement
Object Methods vs Class (Static) Methods (API)
Created by: Barb Ericson
Georgia Institute of Technology
1. Use the API for the String class (java.lang.String) to answer the following:
a. How would you find the first position in a string of another string?
b. How would you find the last position in a string of another string?
c. How would you remove leading and trailing spaces from a string?
d. How do you get the number of characters in a string?
e. How do you convert a string to lowercase letters?
f. How can you tell if two strings have the same characters?
g. How can you convert a number to a string?
2. Use the API for the Math class (java.lang.Math) to answer the following:
a. How can you use the Math class to calculate 2 to the 10th power?
b. How can you use the Math class to find the square root of a number?
c. How can you use the Math class to round a decimal number?
d. Are there any methods in the Math class that aren’t class methods?
3. Use the API for the Integer class (java.lang.Integer) to answer the following:
a. What method can you use to convert a string to an integer value?
b. What happens if you try to convert a string that doesn’t contain a number?
c. Are there any methods in the Integer class that aren’t class methods?
4. Use the API for the Double class (java.lang.Double) to answer the following:
a. What method can you use to convert a string to a double value?
b. What happens if you to convert a string that doesn’t contain a valid
decimal?
Download