Algorithm sum(t, n):
Input: tree whose nodes contains integers and a node of the tree
Output: sum of the integers stored
in the nodes of the subtree of tree t rooted at node n
Fibonacci
ExceptionScope
Propagation
public static void fibonacci(String[] args)
{
try
{
int lo = 1;
int hi = 1;
int n = Integer.parseInt(args[0]);
System.out.println(lo);
for (int i = 1; i < n; i++)
{
System.out.println(hi);
int temp = hi;
hi = lo + hi;
lo = temp;
}
}
catch (ArrayIndexOutOfBoundsException e)
{
System.err.println("No command line argument provided");
}
catch (NumberFormatException e)
{
System.err.println("Command line argument " + e.getMessage() + " is not an integer");
}
finally
{
System.out.println("Done!");
}
}