i am trying to find lcm of n numbers and i want my recursion to run upto the last element, but i cant find an efficient method to limit it from going out of bounds at line 41. please suggest any trick.
import java.io.*;
class lcm
{
static int x=1,k=1;
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader (new InputStreamReader(System.in));
System.out.println("enter the limit");
int n= Integer.parseInt(br.readLine());
System.out.println("enter the numbers");
int L;
int arr[]=new int[n];
for(int i=0;i<n;i++)
arr[i]=Integer.parseInt(br.readLine());
L=lc( arr[0],arr[1],arr,n);
System.out.println(L);
}
static int lc(int min, int max, int arr[], int n)
{
int fact;
if(x<=n-1 )
{
for(int i=1;i<=min;i++)
{
fact=max*i;
if(fact%min==0)
{
k=fact;
break;
}
}
//System.out.println("values of x"+x);
//System.out.println("values of k"+k);
x++;
return lc(arr[x],k,arr,n);
}
else
{
//System.out.println("vale of x"+x);
return k;
}
}
}