首页 > 试题广场 >

What’s the output of&n...

[不定项选择题]
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;
  }
  
}
  • 0
  • 1
  • 2
  • Throws exception

这道题你会答吗?花几分钟告诉大家答案吧!