比如說 費伯納西數列 要只能輸入正數
public static int fib(int n) throws MyException {
if(n<=-1) {
throw new MyException("需要正數");
}else if(n==1) {
return 1;
}else if(n==0) {
return 0;
}else {
return fib(n-1)+fib(n-2);
}
}
有其他的方法 需要只寫在方法裡面的話 不知道有沒有類似的用法呢?
錯誤訊息
No enclosing instance of type Trn1 is accessible. Must qualify the allocation
with an enclosing instance of type Trn1 (e.g. x.new A()
where x is an instance of Trn1).