Try to look at the code given below
Code:
import java.util.StringTokenizer;
public class phone_Tokens {
public static void main (String[] args) {
String areacode, exchange, extension;
// Creates tokens that are delimited by a dash, thus
// (nnn) is one token, nnn is the next, and the last is nnnn
StringTokenizer phone = new StringTokenizer ("(nnn)-nnn-nnnn", "-");
areacode = phone.nextToken();
exchange = phone.nextToken();
extension = phone.nextToken();
System.out.println ("Areacode: " + areacode);
System.out.println ("Exchange: " + exchange);
System.out.println ("Extension: " + extension);
}
}
If you only need the three numbers inside the () for the area code, then see if you can figure out how to use an available String method to do so.
Bookmarks