Try It Yourself: characters and strings

  1. Write a code fragment to identify and print out all the characters in a given string text that are not letters or digits.


  2. Given a string number that contains only digits (for example, "2563"), write a code fragment that converts number to its (positive) integer equivalent (for example, 2563).


  3. Extend your answer for #2 to handle negative integers.


  4. Using only methods to modify a StringBuffer, change the phrase "bowing mink" to "bowling donkey". You may assume that phrase is a StringBuffer object that has been created and initialized to "bowing mink".


  5. Write a Date class. It must contain (at least) the following public methods:
    Date(int m, int d, int y) Creates a Date object with the given month (1 <= m <= 12), day (1 <= d <= 31), and year (1000 <= y <= 9999).
    int getMonth() Returns the month.
    int getDay() Returns the day.
    int getYear() Returns the year.
    String toString() Returns a string representation of the Date object (suitable for printing). The date is represented in the format mm/dd/yyyy (e.g. 3/29/2000).