 |
|
|
Rec.java
|
/*
* Author: Havard Rast Blok
* E-mail: 
* Web : www.rememberjava.com
*/
/*
* Recursive counting
*/
public class Rec
{
public Rec()
{
countBack1( 1, 5 );
countBack2( 5, 1 );
}
public void countBack1( int i, int stop )
{
//notce the the order of the recrusive call and the print line
if( i < stop )
{
countBack1( i+1, stop );
System.out.println(""+i);
}
}
public void countBack2( int i, int stop )
{
if( i >= stop )
{
System.out.println(""+i);
countBack2( i-1, stop );
}
}
public static void main( String args[] )
{
new Rec();
}
}
|
|
|
 |