我是编码新手,我试图让用户输入他的名字,如果用户的名字不在 3 到 256 之间,他必须重新输入他的名字! 这是到目前为止我的代码...
public static void main(String[] args) {
String userName = "";
do {
System.out.print("Enter your name (between 3 and 256 characters) :");
Scanner name = new Scanner(System.in);
userName = name.nextLine();
if ((userName.length() < 3) && (userName.length() > 256));
System.out.println("the length is not good");
} while ((userName.length() < 3) && (userName.length() > 256));
}
最佳答案
两个问题
if ((userName.length() < 3) && (userName.length() > 256));
System.out.println("the length is not good");
删除第一行的分号
将&&
更改为||
关于java - 询问用户名并检查长度是否在 3 到 256 个字符之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35139908/