-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackTrace.java
More file actions
63 lines (49 loc) · 962 Bytes
/
StackTrace.java
File metadata and controls
63 lines (49 loc) · 962 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package stackTrace;
import java.util.*;
public class StackTrace {
/**
*
*
* @param args
*/
public static int factorial(int n){
System.out.println("factorial("+n+");");
Throwable t=new Throwable();
StackTraceElement[] frames=t.getStackTrace();
for(StackTraceElement f:frames){
System.out.println(f);
}
int r;
if(n<=1)
r=1;
else
r=n*factorial(n-1);
System.out.print("return"+r);
return r;
}
/**
* test finally return
* @param args
*/
public static int f(int n){
try{
int r=n*n;
return r;
}finally{
if(n==2)
return 0;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in=new Scanner(System.in);
// System.out.print("Enter n:");
// int n=in.nextInt();
// int m=in.nextInt();
// String s=in.nextLine();
// System.out.println(s);
// System.out.println(m+","+n);
// factorial(n);
System.out.println(f(2));
}
}