Although this seems okay to me the third requirement is not being fulfilled
package com.codegym.task.task09.task0902;
/*
Stack trace revisited
*/
public class Solution {
public static void main(String[] args) throws Exception {
//System.out.println(method1());
method1();
}
public static String method1() {
method2();
StackTraceElement[] element = Thread.currentThread().getStackTrace();
// System.out.println("method 1 "+ element[2].getMethodName());
return element[2].getMethodName();
//write your code here
}
public static String method2() {
method3();
StackTraceElement[] element = Thread.currentThread().getStackTrace();
//System.out.println("method 2 "+ element[2].getMethodName());
return element[2].getMethodName();
}
public static String method3() {
method4();
StackTraceElement[] element = Thread.currentThread().getStackTrace();
//System.out.println("method 3 "+ element[2].getMethodName());
return element[2].getMethodName();
}
public static String method4() {
method5();
StackTraceElement[] element = Thread.currentThread().getStackTrace();
//System.out.println("method 4 "+ element[2].getMethodName());
return element[2].getMethodName();
}
public static String method5() {
StackTraceElement[] element = Thread.currentThread().getStackTrace();
//System.out.println("method 5 "+ element[2].getMethodName());
return element[element.length-5].getMethodName();
}
}