Help with java StringTokenizer

Joined
Dec 18, 2008
Messages
1
Reaction score
0
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 ());
}
}
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top