What’s the output of&n...
发布于 2022-03-03 17:31:15
What’s the output of following code? (单选)
class MyCode {
public static void main (String[] args) {
System.out.println(calc(30) % 3)
}
private static ArrayList<Long> arr = new ArrayList<Long>()
static {
arr.add(1L)
arr.add(1L)
}
private static Long calc(int x) {
if (arr.size() > x) {
return arr.get(x)
}
Long result = calc(x - 1) + calc(x - 2)
arr.add(result)
return result
}
}
class MyCode {
public static void main (String[] args) {
System.out.println(calc(30) % 3)
}
private static ArrayList<Long> arr = new ArrayList<Long>()
static {
arr.add(1L)
arr.add(1L)
}
private static Long calc(int x) {
if (arr.size() > x) {
return arr.get(x)
}
Long result = calc(x - 1) + calc(x - 2)
arr.add(result)
return result
}
}
登录后免费查看答案
关注者
0
被浏览
19