0
我需要帮助我检查日志中的checkstyle错误。我已经尝试了所有错误是在我的布尔方法。这是说,我的嵌套if else在1时它应该是零。这是我所有的if语句。我的另一个错误是,我的方法有3个返回和checkstyle说,最大值是2.我只是想摆脱自己的这些错误可以有人请帮助我。修复checkstyle错误
public class Password {
private String potentialpassword;
private static final String SPECIAL_CHARACTERS = "[email protected]#$%^&*()~`-=_+[]{}|:\";',./<>?";
/**
* initializes the potential password and takes it as a string.
*
* @param potentialpassword
* takes in the potential password
*
*/
public Password(String potentialpassword) {
super();
this.potentialpassword = potentialpassword;
}
/**
* The purpose of this method is to validate whether the password meets the
* criteria that was given
*
* @param potentialpassword
* allows a string potential password to be accepted.
* @return true or false if the method fits a certain guideline.
* @precondition password has to be greater than 6 characters long. password
* also cannot contain any whitespace and the digits cannot be
* less than one.
*/
public static boolean isValid(String potentialpassword) {
if (potentialpassword.length() < 6) {
return false;
} else {
char x;
int count = 0;
for (int i = 0; i < potentialpassword.length(); i++) {
x = potentialpassword.charAt(i);
if (SPECIAL_CHARACTERS.indexOf(String.valueOf(x)) >= 1) {
return true;
}
if (Character.isWhitespace(x)) {
return false;
}
if (Character.isDigit(x)) {
count++;
} else if (count < 1) {
return false;
}
}
return true;
}
}
/**
* Print the potential string characters on a separate line.
*
* @return the potential password characters on each line.
*
*
*/
public String toString() {
String potentialpassword = "[email protected]";
for (int i = 0; i < potentialpassword.length(); i++) {
System.out.println(potentialpassword.charAt(i));
}
return potentialpassword;
}
}
你确定你的算法是正确的吗?在我看来,您拒绝以纯文字开头的密码。 –