WAP to input two numbers(Scanner class) and calculate their LCM value using while loop in java.
Answers
Answered by
4
Your Answer :-
import java.util.Scanner;
public class LCM {
public static void main(String[] args) {
int lcm , a , b;
Scanner obj = new Scanner(System.in);
System.out.println("Enter value of a");
a = obj.nextInt();
System.out.println("Enter value of b");
b = obj.nextInt();
lcm = (a > b) ? a : b;
while(true)
{
if( lcm % a == 0 && lcm % b == 0 )
{
System.out.println("The LCM is = " +lcm);
break;
}
++lcm;
}
}
}
^_^ ^_^
#Be Brainly
Attachments:
Ankit02:
thanks .
Similar questions