简体   繁体   English

在java中,是否可以将字符分配为true或false语句?

[英]In java, is it possible to assign a character as a true or false statement?

System.out.println("Enter Y/N for yes or no respectively if you wish for these features");                                    
System.out.print("Central vacuum: ");
check1 = sc.nextBoolean();

Is is possible to make it that if Y = true and N = false?如果 Y = true 且 N = false ,是否有可能做到这一点?

NO, it is not possible.不,这是不可能的。

But you can simply read a char by the Scanner , and compare it against expected inputs ( 'Y' , 'N' ).但是您可以简单地通过Scanner读取char ,并将其与预期输入( 'Y''N' )进行比较。 Easy enough with an if or switch .使用ifswitch足够简单了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM