In this example of recursion, how would this help me to make a program thats outputs this:
*****
****
***
**
*
*
**
***
****
*****
yes i know its easy with println() and for method but my teacher told me this way. just give any suggested method to do this plz ....though im not sure if i still use arrays for it, if so do i declare string or char.
thanks
CODE
import java.io.*;
public class Recursion
{
public static void main(String[] args)
{
int[] intArray = {23,43,35,38,67,12,76,10,34,8};
System.out.println("The largest element in intArray: " +largest(intArray, 0, intArray.length - 1));
}
public static int largest(int[] list, int lowerIndex, int upperIndex)
{
int max;
if(lowerIndex == upperIndex)
{
return list[lowerIndex];
}
else
{
max = largest(list, lowerIndex + 1, upperIndex);
if(list[lowerIndex] >= max)
{
return list[lowerIndex];
}
else
{
return max;
}
}
}
}