-2

how can i calculate the GCD and LCM of 5 numbers using a loop that i should create?? this is what i started doing but i think i started in wrong way from the beginning can anyone help

        public static void main(String[] args) {
    // TODO Auto-generated method stub
    Scanner input=new Scanner(System.in);
    int nbr1=input.nextInt();
    int nbr2=input.nextInt();
    int nbr3=input.nextInt();
    int nbr4=input.nextInt();
    int nbr5=input.nextInt();
    for(int i=nbr1;(i%nbr2==0 || i%nbr3==0 ||i%nbr3||i%nbr4==0 || i%nbr5==0 ;i++)
    {       
    }
}
}
Santhosh
  • 8,181
  • 4
  • 29
  • 56
  • You should add input.nextLine() in between every nextInt(). – ha9u63a7 Nov 04 '14 at 11:30
  • possible duplicate of [How to find GCF, LCM on a set of numbers](http://stackoverflow.com/questions/4201860/how-to-find-gcf-lcm-on-a-set-of-numbers) – Santhosh Nov 04 '14 at 11:31

1 Answers1

0

You should be using arrayOfInts in java for calculating GCD and LCM of multiple numbers and possibly this link can guide you better.

Community
  • 1
  • 1
sTg
  • 4,313
  • 16
  • 68
  • 115