展开全部
你把zeroException类放在了Shiyan8_7类里面了。
这主要是你写代码e68a843231313335323631343130323136353331333363373737不规范造成的。
下面是正确的:public class Shiyan8_7 {
public static void main(String[] args) {
A a=new A();
int b;
Scanner reader= new Scanner(System.in);
b=reader.nextInt();
try{
a.f(b);
}catch(zeroException x){
System.out.println(x.getMessage());
}
}
}
class zeroException extends Exception{
String message;
zeroException(int n){
message=n+"不是正数";
}
public String getMessage(){
return message;
}
}
class A{
public void f(int m) throws zeroException{
if(m<0){
zeroException ex=new zeroException(m);
throw(ex);
}
double number=Math.sqrt(m);
System.out.println(m+"的平方根是"+number);
}
}