如何检查扫描仪输入是否为空并将变量分配给空白字符串?覆盖初始字符串?
尝试了以下代码,但它不起作用。
System.out.print("Username: ");
String username = sc.nextLine();
int u1nameLength = username.length();
if (u1nameLength == 0) {
String username = "Dude"; //generate replacement username
}
System.out.print("Phone Number: ");
String phoneNumber = sc.nextLine();
慕沐林林
翻过高山走不出你
随时随地看视频慕课网APP
相关分类