![](/img/trans.png)
[英]Finding a word in file storing it in an array list and making sure that word isn't accounted for more than once?
[英]making sure a word is a specific length
我是新来的,我正在制作一个程序,允许一个人注册一些东西。 它接受用户名,将其与其他人进行比较,如果它是唯一的,则允许它。 但是,当他们输入密码时,我不知道如何确保该字数超过8位。 我需要能够将密码与某些东西进行比较,并且只有在密码超过8位时才允许密码。 谢谢!
您应该将密码接受为String类型。 然后使用String.equals(String otherWord)
方法将其与其他String进行比较,并使用String.length()
方法检查它的长度,如下所示: -
Scanner s=new Scanner(System.in);
boolean flag=true;
String pwd="";
while(flag) {
pwd=s.nextLine();
if(pwd.length()>8 && pwd.equals("IntendedWord"))
// set flag=false AND then continue your intended action...
else
System.out.println("Please try again");
}
尝试这样的事情:
// Previous code gets the value for the field and stores it in String pass
if ( pass.length() > 8 )
{
// it is valid. Hash and save
}
else
{
// Not valid. Let user know and ask for reentry.
}
//etc.
您可以将此检查和其他检查置于验证功能中,并在存储之前调用它。
如果您还有其他需要,请告诉我。
另外,有两件事要学习Stack Overflow作为礼貌。 请在发布前搜索与您类似的问题。 第二,在发布时提供更多信息,这样人们就不必猜测你想要/需要什么。
你可以用类似的东西
if(password.length() > 8)
{
//some logic
}
也就是说,考虑到您将密码作为字符串值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.