问题在代码中已标出,请大婶解疑,能不能这样做,这样做能不能实现
import javax.swing.JOptionPane;
public class PasswdException extends Exception {
PasswdException(int i) {
if (i < 6) {
System.out.println("密码不能小于六位");
}
if (i > 6) {
System.out.println("密码不能大于六位");
}
}
//内部类
public class PasswdExceptionisnum {
PasswdExceptionisnum(String j) {
try {
Integer.parseInt(j);
} catch (NumberFormatException e) {
System.out.println("不是数字" + e);
}
}
}
}
class Passwd {
public static boolean checkpasswd(String passwd) throws PasswdException {
if (passwd.length() == 6) {
return true;
} else
throw new PasswdException(passwd.length());
if (passwd != null) {
//问题在下一行,请问怎么实现下一行效果
throw new PasswdException.PasswdExceptionisnum(passwd);
//上面一行行错误,这里想抛出PasswdExceptionisnum内部类
}
}
public static void main(String args[]) {
try {
String passwd = JOptionPane.showInputDialog(" 请设置初始密码");
checkpasswd(passwd);
System.out.println("密码已经设置");
} catch (PasswdException e) {
System.out.println(e);
} finally {
System.out.println("程序结束");
}
}
}