Tài liệu Sample output from the Duck, Duck, Goose program.

Thảo luận trong 'Thiết Kế Web' bắt đầu bởi Thúy Viết Bài, 5/12/13.

  1. Thúy Viết Bài

    Thành viên vàng

    Bài viết:
    198,891
    Được thích:
    173
    Điểm thành tích:
    0
    Xu:
    0Xu
    Recursion
    We have seen that repetition can be achieved by writing loops, such as for loops and
    while loops. Another way to achieve repetition is through recursion, which occurs
    when a function calls itself. We have seen examples of methods calling other
    methods, so it should come as no surprise that most modern programming languages,
    including Java, allow a method to call itself. In this section, we will see why this
    capability provides an elegant and powerful alternative for performing repetitive
    tasks.
    The Factorial function
    To illustrate recursion, let us begin with a simple example of computing the value
    of the factorial function. The factorial of a positive integer n, denoted n!, is defined
    as the product of the integers from 1 to n. If n = 0, then n! is defined as 1 by
    convention. More formally, for any integer n ≥ 0
     

    Các file đính kèm: