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.
views:
27answers:
2
A:
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
2010-02-26 03:46:13
I'm not sure how to use this
Kat
2010-02-26 03:47:26
You might want to start at the very beginning then: http://java.sun.com/docs/books/tutorial/java/data/strings.html
matt b
2010-02-26 03:52:16
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
2010-02-26 04:00:52
+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
2010-02-26 03:48:10