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);
}
}
求帮助 为什么这个还是会抛出异常
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-