TAKING THE NUMBERS FROM THE USER AND GIVING THE LCM OF THESE NUMBERS
package mypro;
import java.util.Scanner;
public class LCMOFUSERENTERNUMBER {
public static void main(String[] args) {
System.out.println("How many numbers's LCM you wanna know, Max length is 6 ");
Scanner obj = new Scanner(System.in);
int n= obj.nextInt();
if(n>6) {
System.out.println("Length is over enter again");
System.exit(0);
}
int i;
switch(n) {
case 1:
System.out.println("Paagal hai kya ?");
break;
case 2:
System.out.println("Enter the numbers ");
int a= obj.nextInt();
int b= obj.nextInt();
for(i=b; i<=a*b; i++) {
if(i%a==0 && i%b==0) {
System.out.println("Lcm is "+i);
break;
}
}
case 3:
System.out.println("Enter the numbers ");
int a1= obj.nextInt();
int b1= obj.nextInt();
int c1= obj.nextInt();
for(i=b1; i<=a1*b1*c1; i++) {
if(i%a1==0 && i%b1==0 && i%c1==0) {
System.out.println("Lcm is "+i);
break;
}
}
case 4:
System.out.println("Enter the numbers ");
int a2= obj.nextInt();
int b2= obj.nextInt();
int c2= obj.nextInt();
int d2= obj.nextInt();
for(i=b2; i<=a2*b2*c2*d2; i++) {
if(i%a2==0 && i%b2==0 && i%c2==0 && i%d2==0) {
System.out.println("Lcm is "+i);
break;
}
}
case 5:
System.out.println("Enter the numbers ");
int a3= obj.nextInt();
int b3= obj.nextInt();
int c3= obj.nextInt();
int d3= obj.nextInt();
int e3 =obj.nextInt();
for(i=b3; i<=a3*b3*c3*d3*e3; i++) {
if(i%a3==0 && i%b3==0 && i%c3==0 && i%d3==0 && i%d3==0&& i%e3==0) {
System.out.println("Lcm is "+i);
break;
}
}
break;
case 6:
System.out.println("Enter the numbers ");
int a4= obj.nextInt();
int b4= obj.nextInt();
int c4= obj.nextInt();
int d4= obj.nextInt();
int e4= obj.nextInt();
int f4= obj.nextInt();
for(i=b4; i<=a4*b4*c4*d4*f4; i++) {
if(i%a4==0 && i%b4==0 && i%c4==0 && i%d4==0 && i%d4==0&& i%e4==0&& i%e4==0) {
System.out.println("Lcm is "+i);
break;
}
}
break;
}
}
}
Comments
Post a Comment