/** * Title: Chapter 4, "Methods" * Description: Examples for Chapter 4 * Copyright: Copyright (c) 2000 * Company: Armstrong Atlantic State University * @author Y. Daniel Liang * @version 1.0 */ // ComputeFactorial.java: Compute factorial of an integer // package chapter4 public class ComputeFactorial { public static void main(String[] args) { // Prompt the user to enter an integer System.out.println("Please enter a nonnegative integer"); int n = MyInput.readInt(); System.out.println("Factorial of " + n + " is " + factorial(n)); } /**Recursive method for computing factorial of n*/ static long factorial(int n) { if (n == 0) // Stopping condition return 1; else return n*factorial(n-1); // Call factorial recursively } }