mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-06 17:29:31 +08:00
refactor: LeastCommonMultiple
(#5435)
* refactor: LeastCommonMultiple * checkstyle: fix formatting --------- Co-authored-by: alxkm <alx@alx.com>
This commit is contained in:
@ -1,41 +1,27 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* Is a common mathematics concept to find the smallest value number
|
||||
* that can be divide using either number without having the remainder.
|
||||
* https://maticschool.blogspot.com/2013/11/find-least-common-multiple-lcm.html
|
||||
* @author LauKinHoong
|
||||
*/
|
||||
|
||||
public final class LeastCommonMultiple {
|
||||
private LeastCommonMultiple() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Driver Code
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
Scanner input = new Scanner(System.in);
|
||||
System.out.println("Please enter first number >> ");
|
||||
int num1 = input.nextInt();
|
||||
System.out.println("Please enter second number >> ");
|
||||
int num2 = input.nextInt();
|
||||
System.out.println("The least common multiple of two numbers is >> " + lcm(num1, num2));
|
||||
input.close();
|
||||
}
|
||||
|
||||
/*
|
||||
* get least common multiple from two number
|
||||
* Finds the least common multiple of two numbers.
|
||||
*
|
||||
* @param num1 The first number.
|
||||
* @param num2 The second number.
|
||||
* @return The least common multiple of num1 and num2.
|
||||
*/
|
||||
public static int lcm(int num1, int num2) {
|
||||
int high;
|
||||
int num3;
|
||||
int cmv = 0;
|
||||
/*
|
||||
* value selection for the numerator
|
||||
*/
|
||||
|
||||
if (num1 > num2) {
|
||||
high = num1;
|
||||
num3 = num1;
|
||||
|
Reference in New Issue
Block a user