Incorrect output (none) for this simple program (when
enter "java Fibo 10" should get "fibonacci(10) = 55"
import java.lang.*;
class Fibo {
private static int fib (int x) {
if (x > 1)
return (fib(x - 1) + fib(x - 2));
else return (x);
}
public static void main(String args[]) throws
Exception {
int number = 0, value;
try {
number = Integer.parseInt(args[0]);
} catch (Exception e) {
System.out.println ("Input error");
System.exit (1);
}
value = fib(number);
System.out.println ("fibonacci(" + number + ")
= " + value);
}
}
Gets the close curly bracket at the end of the catch
clause wrong (version 1.4.1) (partial output):
try {
i = Integer.parseInt(stringArr[0]);
}
catch (Exception exception) {
System.out.println("Input error");
System.exit(1);
k = Fibo_jrp.fib(i);
System.out.println(new
StringBuffer().append("fibonacci(").append(
i).append(") = ").append(k).toString());
return;
}
Obviosuly, the close curly bracket needs to be after
the "exit(1);".
.class for the given test code