BigIntegerFib lol
This commit is contained in:
35
BigIntegerFibonacci/src/bigintegerfibonacci/StackSize.java
Normal file
35
BigIntegerFibonacci/src/bigintegerfibonacci/StackSize.java
Normal file
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package bigintegerfibonacci;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author caleb
|
||||
*/
|
||||
public class StackSize {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
try {
|
||||
//System.out.println(fact(1 << 15));
|
||||
System.out.println(infinateRecursion(0));
|
||||
}
|
||||
catch (StackOverflowError e) {
|
||||
System.err.println("true recursion level was " + level);
|
||||
System.err.println("reported recursion level was " +
|
||||
e.getStackTrace().length);
|
||||
}
|
||||
}
|
||||
|
||||
private static int level = 0;
|
||||
public static long fact(int n) {
|
||||
level++;
|
||||
return n < 2 ? n : n * fact(n - 1);
|
||||
}
|
||||
public static long infinateRecursion(long n) {
|
||||
level++;
|
||||
return infinateRecursion(n++);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user