除了有一个空格之外不应假设的输入数据
我正在编写一个程序,要求用户输入他们的出生日期。对于它,我不知道如何输入数字数据,除了月、日和年之间有一个空格。现在,我让它在一行上将日期作为字符串读取,但我不确定如何做到这一点,以使其符合程序的规范。
使用 nextInt()
似乎是可行的方法,但我不确定。
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.
Using nextInt()
seemed like the way to go but I'm not sure.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一个包含以下内容的字符串:
您还可以使用 split 方法,因此给出您的字符串“readfrominput”:
If you've got a string containing:
You might also use the split method, so given your string "readfrominput":
String.trim():
String.trim():