Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Help with java StringTokenizer

Thread Tools

Help with java StringTokenizer

ronron10 ronron10 is offline
Junior Member
Join Date: Dec 2008
Posts: 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 ());
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
need help with StringTokenizer ros Java 2 05-06-2007 08:28 AM
StringTokenizer Question? Jim Crowell Java 9 08-23-2003 06:28 PM
Read data with delimater using stringtokenizer Liang Yew Java 3 07-21-2003 07:10 AM
StringTokenizer help ARMANDO PADILLA Java 3 07-04-2003 04:37 PM
Re: StringTokenizer Help Phil Hanna Java 0 06-30-2003 11:57 PM