添加corejava第11版源码
日期:2019-5-22
This commit is contained in:
1 parent
e199db7c36
commit
af9d779c86
525 files changed
+91425
No files matched your search
@@ -0,0 +1,38 @@
|
||||
package stackTrace;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* A program that displays a trace feature of a recursive method call.
|
||||
* @version 1.10 2017-12-14
|
||||
* @author Cay Horstmann
|
||||
*/
|
||||
public class StackTraceTest
|
||||
{
|
||||
/**
|
||||
* Computes the factorial of a number
|
||||
* @param n a non-negative integer
|
||||
* @return n! = 1 * 2 * . . . * n
|
||||
*/
|
||||
public static int factorial(int n)
|
||||
{
|
||||
System.out.println("factorial(" + n + "):");
|
||||
var walker = StackWalker.getInstance();
|
||||
walker.forEach(System.out::println);
|
||||
int r;
|
||||
if (n <= 1) r = 1;
|
||||
else r = n * factorial(n - 1);
|
||||
System.out.println("return " + r);
|
||||
return r;
|
||||
}
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
try (var in = new Scanner(System.in))
|
||||
{
|
||||
System.out.print("Enter n: ");
|
||||
int n = in.nextInt();
|
||||
factorial(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user