public class Solution {
    public static void main(String[] args) throws Exception {
        int deep = getStackTraceDepth();

    }

    public static int getStackTraceDepth() {
        // write your code here
        StackTraceElement[] element = Thread.currentThread().getStackTrace();
        System.out.println(Arrays.toString(element));
        return element.length;
    }
}
Any idea?