|
Last change
on this file since 1389 was 1389, checked in by bird, 22 years ago |
|
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
|
|
File size:
633 bytes
|
| Line | |
|---|
| 1 | public class inline
|
|---|
| 2 | {
|
|---|
| 3 | static int factorial_1 (int n)
|
|---|
| 4 | {
|
|---|
| 5 | if (n > 0)
|
|---|
| 6 | return n * factorial_1(n-1);
|
|---|
| 7 | return 1;
|
|---|
| 8 | }
|
|---|
| 9 |
|
|---|
| 10 | static int factorial_2 (int n)
|
|---|
| 11 | {
|
|---|
| 12 | if (n > 0)
|
|---|
| 13 | return n * factorial_3(n-1);
|
|---|
| 14 | return 1;
|
|---|
| 15 | }
|
|---|
| 16 |
|
|---|
| 17 | static int factorial_3 (int n)
|
|---|
| 18 | {
|
|---|
| 19 | if (n > 0)
|
|---|
| 20 | return n * factorial_2(n-1);
|
|---|
| 21 | return 1;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | public static void main(String args[])
|
|---|
| 25 | {
|
|---|
| 26 | if (factorial_1 (5) != 120)
|
|---|
| 27 | System.out.println("This should not happen");
|
|---|
| 28 | else
|
|---|
| 29 | System.out.println("OK");
|
|---|
| 30 | if (factorial_2 (5) != 120)
|
|---|
| 31 | System.out.println("This should not happen");
|
|---|
| 32 | else
|
|---|
| 33 | System.out.println("OK");
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.