help please Write a program that reads in two positive integ


help please?

Write a program that reads in two positive integers and prints out the least common multiple (LCM). The least common multiple is the number that both positive integers divide into evenly.

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

 help please? Write a program that reads in two positive integers and prints out the least common multiple (LCM). The least common multiple is the number that b
 help please? Write a program that reads in two positive integers and prints out the least common multiple (LCM). The least common multiple is the number that b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site