Close
Close

whats wrong in the logic of this program for finding lcm of n numbers?

   Revanth Konduru

package revanthworkspace;
import java.util.*;
public class RevanthWorkspace {
            static int  count=0;
    public static void main(String[] args){
        
        Scanner sc=new Scanner(System.in);
        System.out.println("enter no of numbers");
        int n=sc.nextInt();
        int[] arr=new int[n];
                System.out.println("enter  numbers");
        for(int i=0;i<n;i++)
        {
            arr[i]=sc.nextInt();
        }
        for(int j=2;j<=j+1;j++)    
        {
                    for(int i=0;i<n;i++)
                    {
                        if(j%arr[i]==0&&(i<n))
                        {
                           count++;
                                                                 
                        }
                    
                       if(count==n-1)
                        {
                       System.out.println("lcm is"+j);
                       break;
                        }
                    }
        }
}       
}  
    


Answers

Ask Yours
Post Yours
Write your answer