Stack trace with 10 calls

• 3
• Locked
I got lucky: My favorite elementary school, Mrs. Turing, always wrote this phrase on the blackboard: "The last function called is the first function to end". She made us memorize it and swore that one day we would understand. Thank you, Mrs. Turing. It seems the promised day has come. I can even write code to get a stack trace that is 10 calls deep. Can you?
You can't complete this task, because you're not signed in.
joe
Level 27 , London, United Kingdom
14 August 2020, 10:24
method 1 calls : getStackTrace(), method10() to method1() & main = 12 method 10 calls: getStackTrace(), method10() & main = 3
Nikolaos
27 August 2019, 16:29
I have solve it also, but i don't underastand it yet. I hope, it will be more cleal in the next lessons.
jonathan D
Level 26 , Lille, France
14 September 2019, 16:35
I think the logic is this: 1- We set the stack trace in method10() 2- We call method1() and method10() from main() in this line: int stackTraceLength = method1().length - method10().length + 1; For the method1() call: when we reach the stack trace in method10() we go back and come across: getStackTrace() -> methods(from 10 to 1) -> main() == 12 For the method10() call: when we reach the stack trace in method10() we go back and come across: getStackTrace() -> method10() -> main() == 3 and 12 - 3 +1 = 10. You can check that if you comment the line 10 with the variable stackTraceLength in main() and write:
``````StackTraceElement[] x = method1();   // or method10()
for(StackTraceElement element : x)
System.out.println(element.getMethodName());``````
yehuda b
Level 23 , Beersheba, Israel
11 February 2020, 17:42
Thanks! very clear!
Khairul
Level 11
15 May 2019, 09:10
I have solved it. I understand why is the value of method10().length is equal to 12. Because all of the previous method and the method10 and the stackTrace method is in the Stack. --------------------------------------------------------------------------------------------------------------- But can you tell me, why is the value of method1().length is 21?
Ahmed
Level 23 , Amsterdam, Netherlands
15 May 2019, 11:08
the value of method1().length is 12 and the value of method10().length is 3 put a breakpoint on the main method and you will see
Khairul
Level 11
15 May 2019, 12:08
Can you clarify it a little bit more with example?
Ahmed
Level 23 , Amsterdam, Netherlands
15 May 2019, 12:53