如何在扫描仪类的单行输入日月? [英] How to enter day month year in single line for scanner class?

查看:86
本文介绍了如何在扫描仪类的单行输入日月?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

扫描仪控制台=新扫描仪(System.in);

System.out.print(输入生日(dd mm yyyy)老人:);

int days = console.nextInt();

int months = console.nextInt();

int years = console.nextInt();

if((days> = 30&& months> = 9&& years> = 1932)&&(天< = 30&&月< = 9&& years< = 1962))

System.out.println(>> ;>不符合每月支付的条件。原因:符合资格期后的差异);

其他

{



System.out.println(>>>不符合每月付款的条件。原因:不是老人);

}



我尝试过:



大家好,请指教。现在我的问题是我要键入3个数字,其中int天,月,年在单行扫描仪中,但不幸的是,当我按回车键时,程序将在int天数一次键入下一行。



i知道C程序允许在单行输入很多int数,但是java怎么样?谢谢你的建议。

Scanner console = new Scanner(System.in);
System.out.print("Enter birthdate (dd mm yyyy) of elderly: ");
int days = console.nextInt();
int months = console.nextInt();
int years = console.nextInt();
if ((days >= 30 && months >= 9 && years >= 1932) && (days <= 30 && months <= 9 && years <= 1962) )
System.out.println(">>> Not Eligible for monthly payout. Reason: Diasabilities after qualifying period");
else
{

System.out.println(">>> Not Eligible for monthly payout. Reason: Not an elderly" );
}

What I have tried:

Hi all, please advice me. now my problem is i want to key in 3 number which int days, months, years in single line of scanner, but unfortunately when i press enter, program will go to next line once key in number for int days.

i know that C program allow many int number input in single line, but how about the java? thanks for advice.

推荐答案

使用 Scanner.nextLine() [ ^ ]读取完整的一行。但是,您需要使用 String 方法来分隔各个字段。
Use Scanner.nextLine()[^] to read a complete line. But you will then need to use String methods to separate the individual fields.


这篇关于如何在扫描仪类的单行输入日月?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆