Recursion in Java

1. ## Recursion in Java

hey guys i wrote up a quick program and it is suppose to take in the values from an array called int [] list and then return the product of all of the numbers stored in int [] list. Anyways, i did this using recursion and my compiler died on me so i was wondering if someone could compile this and tell me if it works...thanks

Code:
```public class Car
{
public void main(String args[])
{
int list[]=null;
list[0]=1;
list[1]=2;
list[2]=3;
wrapper_Mystery(list);
}

public void wrapper_Mystery (int [] list)
{
int n=0;
mystery(list,n);
}
public int mystery(int [] list, int n)
{
if (n&lt;=list.length)
{
return list[n]*mystery(list,n+1);
}
else
return 0;
}
}```
my compiler said that no errors were found, but i just want to check that there is no logic errors. i have never really studied or learned recursion so i am new to all of this h3r3tic if you can help me out i would be appriciative

Edit:

Also while you are at it could someone try to compile the program bellow. All it does is find the biggest number in an array of integers and returns it...
Code:
```public class Car
{
public void main(String args[])
{
int list[]=null;
list[0]=1;
list[1]=2;
list[2]=3;
wrapper_Mystery(list);
}

public void wrapper_Mystery (int [] list)
{
int n=0;
mystery(list,n);
}
public int mystery(int [] list, int n)
{
if (n==list.length-1)
return list[n];
else
{
if (list[n]&gt;mystery(list,n+1))
return list[n];
else
{
return mystery(list, n+1);
}
}
}
}```
thanks guys

2. I've a book on recursion examples. P.S i didn't learn recursion before. Let me type out the examples

Code:
```public class Factorial
{
public long factorial(long number)
{
// base case
if (number &lt;= 1)
{
return 1;
}
//recursive step
else
{
return number * factorial(number - 1);
}
}

public static void main(String args[])
{
Factorial ft = new Factorial();

for (long counter = 0; counter &lt;= 10; ++counter)
{
System.out.println(counter + "! = " +
ft.factorial(counter) + "\n");
}
}
}```
Hope it will helps

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•