How to return a string from char[] array using recursion loop.(java)
- by Daniel
I am very bed in recursion...
I need to convert a char[] array by using recursion loop only, into string.
Without using for(),while()... loops. For example if i have char array: a[0]='H', a[1]='e', a[2]='l',a[3]= 'l',a[4]= 'o',
it returns H e l l o.
What I doing wrong?
public String toFormattedString(char[] a)
{
int temp =a.length;
if (a == null)
return "null";
if (a.length == 0)
return "0";
if( a.length == 1 )
else if( a[0] == a[a.length] )
return toFormattedString (a[a.length -1])+a[a.length];