help please Write a program that reads in two positive integ
help please?
Solution
LCMOfTwoNos.java
import java.util.Scanner;
public class LCMOfTwoNos {
public static void main(String[] args) {
//Declaring variables
int first_num,second_num,high=0,lcm=0,num=1;
//Scanner class object is used to read the inputs entered by the user
Scanner sc=new Scanner(System.in);
//Getting the first number entered by the user
System.out.print(\"Enter a number :\");
first_num=sc.nextInt();
//Getting the second number enterd by the second
System.out.print(\"Enter Another Number :\");
second_num=sc.nextInt();
//This loop continue to execute until finds the LCM
while(true)
{
++num;
//Checking whether the number is divisible by first_name and second_name
if(num%first_num==0 && num%second_num==0)
{
lcm=num;
break;
}
else
{
continue;
}
}
//Displaying the lcm of two numbers
System.out.println(\"Lcm of \"+first_num+\" and \"+second_num+\" is :\"+lcm);
}
}
_______________________
Output1:
Enter a number :2
Enter Another Number :19
Lcm of 2 and 19 is :38
___________________________
Output2:
Enter a number :3
Enter Another Number :21
Lcm of 3 and 21 is :21
______________________________
Output3:
Enter a number :2
Enter Another Number :17
Lcm of 2 and 17 is :34
______________Thank You

