正在加载图片...
Recursive method r An recursive method is a method that contains a statement (or statements) that makes a call to itself r Implementing the factorial of N recursively will result in the following method public int factorial( int N Test to stop or continue if(N==1){ End case return 1 recursion stops Recursive case recursion continues return N factorial( N-1)i C 2000 McGraw-Hill troduction to Object-Oriented Programming with Java--Wu Chapter 16-4© 2000 McGraw-Hill Introduction to Object-Oriented Programming with Java--Wu Chapter 16 - 4 Recursive Method An recursive method is a method that contains a statement (or statements) that makes a call to itself. Implementing the factorial of N recursively will result in the following method. public int factorial( int N ) { if ( N == 1 ) { return 1; } else { return N * factorial( N-1 ); } } Test to stop or continue. Recursive case: recursion continues. End case: recursion stops
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有