views:

27

answers:

2

I'm writing a program that asks the user to enter their birth date. For it, I'm not suppose to know how the numeric data is to be enter except that there is one white space between the month, day and year. Right now, I have it reading the date as a String on one line and I am unsure how to do it so it meets the specifications of the program.

A: 

String.trim():

public String trim()

Returns a copy of the string, with leading and trailing whitespace omitted.

...

This method may be used to trim whitespace (as defined above) from the beginning and end of a string.

matt b
I'm not sure how to use this
Kat
You might want to start at the very beginning then: http://java.sun.com/docs/books/tutorial/java/data/strings.html
matt b
I have no idea who downvoted this, but I'm upvoting because it's a perfectly logical reference to a function containing nothing incorrect and totally relevant to the OPs question.
Ninefingers
+1  A: 

If you've got a string containing:

1 1 2001

You might also use the split method, so given your string "readfrominput":

String[] numbers = readfrominput.split(" "); // space is the default delimiter.
Ninefingers