求帮助 为什么这个还是会抛出异常

package Exception;
import java.util.Scanner;
class TestException extends Exception {
private String msg;
TestException(String s){
msg=s;
}
@Override
public String toString() {
return "["+msg+"]";
}
}
public class Test{
public static void checkpwd(String s) throws TestException{
if(s.equals("")||s.equals(null))
throw new TestException("输入的密码为空");
if(s.length()<6)
throw new TestException("输入的密码长度错误");
for(int i=0;i<s.length();i++) {
while(Character.isLetter(s.charAt(i))) { //用char包装类中的判断字母的方法判断每一个字符
System.out.println("输入正确");
break;
}
if(Character.isLetter(s.charAt(i))==false);
throw new TestException("输入的密码格式错误");
}
}
public static void main(String[] args) throws TestException {
Scanner sc=new Scanner(System.in);
System.out.println("请输入设置密码:");
String line=sc.nextLine();
checkpwd(line);
}

}

图片说明

求大佬帮助下 本人初学者 谢谢啦

不知道你要做什么

while(Character.isLetter(s.charAt(i))) { //用char包装类中的判断字母的方法判断每一个字符
System.out.println("输入正确");
break;
}
if(Character.isLetter(s.charAt(i))==false);
throw new TestException("输入的密码格式错误");
}
其实就是
if(Character.isLetter(s.charAt(i))) { //用char包装类中的判断字母的方法判断每一个字符
System.out.println("输入正确");
}
else
;//请注意这个分号的存在。下面的代码无论如何都会执行。
throw new TestException("输入的密码格式错误");
}

if(Character.isLetter(s.charAt(i))==false);
throw new TestException("输入的密码格式错误");
}

1: if语句后的分号导致if逻辑结束,throw new TestException("输入的密码格式错误");成为下一条必然执行的语句;
2: 12345a中只有a是letter。1,2,3,4,5都是digit。

不妨将
for(int i=0;i<s.length();i++) {
while(Character.isLetter(s.charAt(i))) { //用char包装类中的判断字母的方法判断每一个字符
System.out.println("输入正确");
break;
}
if(Character.isLetter(s.charAt(i))==false);
throw new TestException("输入的密码格式错误");
}
改为
for(int i=0;i<s.length();i++) {
if(Character.isLetter(s.charAt(i))==false && Character.isDigit(s.charAt(i))==false){
throw new TestException("输入的密码格式错误");
}
}
System.out.println("输入正确");