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 spe开发者_运维百科cifications of the program.
Using nextInt()
seemed like the way to go but I'm not sure.
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.
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.
精彩评论