package com.codegym.task.task09.task0902;
/*
Stack trace revisited
*/
public class Solution {
public static void main(String[] args) throws Exception {
method1();
}
public static String method1() {
method2();
//write your code here
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[4];//coz 0th will be getStackTrace so 1st
String methodName = e.getMethodName();
System.out.println(methodName);
return Thread.currentThread().getStackTrace()[0].getClassName();
}
public static String method2() {
method3();
//write your code here
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[3];//coz 0th will be getStackTrace so 1st
String methodName = e.getMethodName();
System.out.println(methodName);
return Thread.currentThread().getStackTrace()[1].getMethodName();
}
public static String method3() {
method4();
//write your code here
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[2];//coz 0th will be getStackTrace so 1st
String methodName = e.getMethodName();
System.out.println(methodName);
return Thread.currentThread().getStackTrace()[2].getMethodName();
}
public static String method4() {
method5();
//write your code here
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[1];//coz 0th will be getStackTrace so 1st
String methodName = e.getMethodName();
System.out.println(methodName);
return Thread.currentThread().getStackTrace()[3].getMethodName();
}
public static String method5() {
//write your code here
StackTraceElement[] stacktrace = Thread.currentThread().getStackTrace();
StackTraceElement e = stacktrace[0];//coz 0th will be getStackTrace so 1st
String methodName = e.getMethodName();
System.out.println(methodName);
return Thread.currentThread().getStackTrace()[4].getMethodName();
}
}
What's wrong with my code?
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Daniel Njuguna
6 February 2019, 16:47
Ok
0
Guadalupe Gagnon
5 February 2019, 14:48
Please don't copy and paste code like this, it is very difficult to read and there are no task requirements. Attach your with the slider bar:
.
0