//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //Solution to Quiz 1: A Recursive Factorial Function //Description: Computes and outputs the factorial of 0 through 15. //CS 284 //Programmed by Jonathan Voris // 1/27/06 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public class factorial { public static void main(String[] args) { for (int x = 0; x < 16; x++) { System.out.println(x + "! = " + factorial(x)); } } //Note: All you needed to write for our quiz was the following function. //I've placed it in a class and called it from a main function //for ease of compilation and testing. static int factorial(int n) { if (n == 0) { return 1; } else { return n * factorial(n-1); } } }