L.B*_*L.B 2 java java.util.scanner
我想做一个不能为空的扫描仪。因此,当扫描仪中没有任何内容时按下 Enter 键时,我想发出警告消息。我有这段代码。
if (user_input.hasNext())// only if scanner is empty and enter is pressed{
System.out.println("Scanner can not be empty");
}
Run Code Online (Sandbox Code Playgroud)
Scanner sc=new Scanner(System.in);
String input = sc.nextLine();
if(input.isEmpty())
{
System.out.println("Scanner can not be empty");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6059 次 |
| 最近记录: |