Want To Contact Us? Use Below Info:
Email: [email protected]
Tel: +234 813 351 7876

Click Below To:?

See Our Official Admins



Own A Blog Like "Aruwa_Ab 9ja"
For Questions, Inquiries, Click Here
Page | Group - Follow us - Call us - Hire Us - [email protected]

Subscribe to our YouTube channel - Here

Want to Upload your song(s) on Aruwa_Ab 9ja Blog? - Click Here

Join Our Music Promotion - ClicK Here To Reach Us
stzblog-bg

Java Program to Find HCF and LCM of Two Numbers

Prompting you the best..... 

In this tutorial, we will write a java program to find the HCF and LCM of two entered numbers.

LCM (Least Common Multiple): The LCM of two numbers is the smallest positive integer which is divisible by both numbers.
HCF (Highest common Factor): HCF is also known as Greatest common divisor, HCF of two numbers is the largest positive integer that divides both the numbers.

Program to Find HCF and LCM of Two Numbers in Java

import java.util.Scanner;

public class JavaExample{
   public static void main(String args[]){
      int temp1, temp2, num1, num2, temp, hcf, lcm;
      Scanner scanner = new Scanner(System.in);

      System.out.print("Enter First Number: ");
      num1 = scanner.nextInt();
      System.out.print("Enter Second Number: ");
      num2 = scanner.nextInt();
      scanner.close();

      temp1 = num1;
      temp2 = num2;

      while(temp2 != 0){
         temp = temp2;
         temp2 = temp1%temp2;
         temp1 = temp;
      }

      hcf = temp1;
      lcm = (num1*num2)/hcf;

      System.out.println("HCF of input numbers: "+hcf);
      System.out.println("LCM of input numbers: "+lcm);
   }
}

Output:
Java Program to Find HCF and LCM of Two Numbers

ALWAYS STAY UPDATED WITH THE LATEST NIGERIAN NEWS FROM ARUWAAB9JA.COM.NG

Post a comment

0 Comments