调试了半天提示
java.lang.NoSuchMethodError: main
Exception in thread "main"
我写的程序在下面,有什么明显的错误吗 ?
public class Solution {
public int JumpFloor(int target) {
if (target <= 0) {
return -1;
} else if (target == 1) {
return 1;
} else {
return 2 * JumpFloor(target - 1);
}
}
public static void main(String[] args) {
Solution st = new Solution();
st.JumpFloor(3);
}
}
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
这个一个斐波那契数列
F(n) = F(n-1) + F(n-2)我觉得你的想法错了。
但看程序不看题,写得没有问题,看不出问题,可编译通过,可以跑。
看似也没有规定青蛙不让往回跳,搂主这个结论
2^(n-1)是否应该在考虑下就是一个简单的递归而已,
只要把初始的两个条件f(1)和f(2)设好liu' han le(就好了)