就是亿个人 2018-10-27 15:29 采纳率: 0%
浏览 525

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

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);
}

}

图片说明

  • 写回答

3条回答 默认 最新

  • 就是亿个人 2018-10-27 15:29
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器