Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何让程序检查输入,如果没有收到输入,程序将跳过命令。我正在尝试制作游戏,并且很好奇是否存在类似的东西。
简单如下
if(input!=null){ // execute }else{ // skip }
假设您的输入将是Scanner通过命令提示符输入的。然后你必须等待用户输入。然后检查(验证)用户输入。如果没有输入null,或者empty你可以继续,否则你可以跳过。
Scanner
null
empty