scp YOURUNIXLOGIN@goldengate.cs.brynmawr.edu:/home/gtowell/Public/151/Data/Lab6/Stack151.java Stack151.java
ArrayStack is incomplete (the methods peek, pop and push are only stubs. A stub method has a correctly first line -- eg "public int getInt() {" -- and a return value that is sufficiently correct to satisfy the compiler and that is all). VSC will often offer to write stub method with you say a class should implement an interface.) Write correct bodies for each of the stub method in the class.
public class Factorial {
public static void main(String[] args) {
String[] defaultArgs = { "5" };
if (args.length == 0)
args = defaultArgs;
try {
int fb = Integer.parseInt(args[0]);
Factorial f = new Factorial();
int b = f.factorial(fb);
System.out.println(b);
} catch (NumberFormatException nfe) {
System.err.println("<<" + args[0] + ">> must be an integer");
}
}
/**
* Compute factorial recursively
* @param n the number whose factorial you want to compute
* @return the factorial of the given number
*/
public int factorial(int n) {
if (n == 1)
return 1;
if (n < 1)
return 0;
int f = factorial(n - 1);
return f*n;
}
}
Get this into VSC (no need for comments).
With this code, set a breakpoint so you can see exactly what the value of f in the factorial function just before the return statement. DO not use a print statement.
- How big a factorial can you compute before the numbers start getting weird.
- What is the value of f just before things get weird.