Help with java StringTokenizer

Discussion in 'Java' started by ronron10, Dec 18, 2008.

  1. ronron10

    ronron10

    Joined:
    Dec 18, 2008
    Messages:
    1
    hi i have this HW assignment and i cant figure it out.... If anyone can help me out i would apprciate it thanks...

    A class that uses the StringTokenizer class to identify
    the parts of a phone number. Assume that the format of the phone
    number is (nnn) nnn-nnnn. Example (860) 222-3344. The class should
    have at least three public methods: one returning the area code,
    one returning the exchange and one returning the extension.

    This is what i came up with....

    import java.util.StringTokenizer;

    class First_Rest {

    public static void main (String[] args) {

    String number = "(203) 919 - 0136";
    StringTokenizer st = new Stringtokenizer (number, "()");
    System.out.println ("Number of tokens = " + st.countTokens ());
    System.out.println ("Area Code = " = st.nextToken ());
    System.out.println ("Exchange = " = st.nextToken (") -"));
    System.out.println ("Extension = " = st.nextToken ());
    }
    }
     
    ronron10, Dec 18, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phil Hanna

    Re: StringTokenizer Help

    Phil Hanna, Jul 1, 2003, in forum: Java
    Replies:
    0
    Views:
    873
    Phil Hanna
    Jul 1, 2003
  2. ARMANDO  PADILLA

    StringTokenizer help

    ARMANDO PADILLA, Jul 4, 2003, in forum: Java
    Replies:
    3
    Views:
    615
    Chris Smith
    Jul 4, 2003
  3. Liang Yew
    Replies:
    3
    Views:
    649
    Jacob
    Jul 21, 2003
  4. Jim Crowell

    StringTokenizer Question?

    Jim Crowell, Aug 20, 2003, in forum: Java
    Replies:
    9
    Views:
    3,768
    Roedy Green
    Aug 23, 2003
  5. ros
    Replies:
    2
    Views:
    464
Loading...

Share This Page