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;
}
}
你確定你的算法是正確的嗎?在我看來,您拒絕以純文字開頭的密碼。 –