The Artima Developer Community
Sponsored Link

Java Answers Forum
StringTokenizer

1 reply on 1 page. Most recent reply: Aug 10, 2002 6:02 AM by thomas

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Jo Dolan

Posts: 1
Nickname: john01
Registered: Aug, 2002

StringTokenizer Posted: Aug 10, 2002 5:32 AM
Reply to this message Reply
Advertisement
i understand that the object stringtokenizer can extract components of a string into its constituent parts! Can I extract the contents of a date string e.g. 23/05/02, which is entered by the user and then convert the day year and month values to int to be displayed? what would this class look like


thomas

Posts: 42
Nickname: turbomanic
Registered: Jul, 2002

Re: StringTokenizer Posted: Aug 10, 2002 6:02 AM
Reply to this message Reply
import java.io.*;
import java.util.*;
public class date{
public static void main(String[] args){

BufferedReader br=new BufferedReader(new InputStreamReader(System.in))//create BufferedReader object
//prompt for date input
String date=br.readLine();

StringTokenizer st=new StringTokenizer(date,"/");
String token=st.nextToken();
int year=Integer.parseInt(token);
token=st.nextToken();
int month=Integer.parseInt(token);
token=st.nextToken();
int day=Integer.parseInt(token);
//now you have all parts you need
if(st.hasMoreTokens())
System.out.println("not formatted properly");
}//end of main
}//end of class

hope this helps

Flat View: This topic has 1 reply on 1 page
Topic: JFrames Previous Topic   Next Topic Topic: Can anyone please help with this problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use