Math Program

Math Program

The greatest common divisor of two integers 16 and 24 is 8.
Develop the algorithm for finding the greatest common divisor of two numbers. Write a program that prompts the user to enter two integers and calculates the GCD for the entered numbers.
View Answers

March 3, 2010 at 11:46 AM

Hi Friend,

Try the following code:

import java.util.*;
class GCD{
public static int determineGCD(int a, int b) {
if (b==0)
return a;
else
return determineGCD(b, a % b);
}
public static void main(String[] args)throws Exception {
GCD cal = new GCD();
Scanner input=new Scanner(System.in);
System.out.println("Enter first number: ");
int num1=input.nextInt();
System.out.println("Enter second number: ");
int num2=input.nextInt();
int gcd = cal.determineGCD(num1, num2);
System.out.println("GCD of two numbers= "+gcd);
}
}


Thanks









Related Tutorials/Questions & Answers:
Math Program - Java Beginners
Math Program  The greatest common divisor of two integers 16 and 24 is 8. Develop the algorithm for finding the greatest common divisor of two numbers. Write a program that prompts the user to enter two integers and calculates
Version of commons-math>commons-math dependency
List of Version of commons-math>commons-math dependency
Advertisements
ModuleNotFoundError: No module named 'ancient_math'
ModuleNotFoundError: No module named 'ancient_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ancient_math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'ancient_math'
ModuleNotFoundError: No module named 'ancient_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ancient_math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'animals-math'
ModuleNotFoundError: No module named 'animals-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'animals-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'animals-math'
ModuleNotFoundError: No module named 'animals-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'animals-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'animals-math'
ModuleNotFoundError: No module named 'animals-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'animals-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'elementary_math'
ModuleNotFoundError: No module named 'elementary_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'elementary_math' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'elementary_math'
ModuleNotFoundError: No module named 'elementary_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'elementary_math' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'euler-math'
ModuleNotFoundError: No module named 'euler-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'euler-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'euler-math'
ModuleNotFoundError: No module named 'euler-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'euler-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'math-braid'
ModuleNotFoundError: No module named 'math-braid'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-braid' How to remove the ModuleNotFoundError: No module named 'math
ModuleNotFoundError: No module named 'math-factors'
ModuleNotFoundError: No module named 'math-factors'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-factors' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'math-fold'
ModuleNotFoundError: No module named 'math-fold'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-fold' How to remove the ModuleNotFoundError: No module named 'math
ModuleNotFoundError: No module named 'math_lw'
ModuleNotFoundError: No module named 'math_lw'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math_lw' How to remove the ModuleNotFoundError: No module named 'math_lw
ModuleNotFoundError: No module named 'math-addition'
ModuleNotFoundError: No module named 'math-addition'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-addition' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'math-braid'
ModuleNotFoundError: No module named 'math-braid'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-braid' How to remove the ModuleNotFoundError: No module named 'math
ModuleNotFoundError: No module named 'math-factors'
ModuleNotFoundError: No module named 'math-factors'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-factors' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'math-fold'
ModuleNotFoundError: No module named 'math-fold'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-fold' How to remove the ModuleNotFoundError: No module named 'math
ModuleNotFoundError: No module named 'math_lw'
ModuleNotFoundError: No module named 'math_lw'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math_lw' How to remove the ModuleNotFoundError: No module named 'math_lw
ModuleNotFoundError: No module named 'math-round'
ModuleNotFoundError: No module named 'math-round'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-round' How to remove the ModuleNotFoundError: No module named 'math
ModuleNotFoundError: No module named 'math_sxt'
ModuleNotFoundError: No module named 'math_sxt'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math_sxt' How to remove the ModuleNotFoundError: No module named 'math_sxt
ModuleNotFoundError: No module named 'math-tokenizer'
ModuleNotFoundError: No module named 'math-tokenizer'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math-tokenizer' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'math_wsh'
ModuleNotFoundError: No module named 'math_wsh'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'math_wsh' How to remove the ModuleNotFoundError: No module named 'math_wsh
ModuleNotFoundError: No module named 'micropython-math'
ModuleNotFoundError: No module named 'micropython-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'micropython-math' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'mo-math'
ModuleNotFoundError: No module named 'mo-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'mo-math' How to remove the ModuleNotFoundError: No module named 'mo-math
ModuleNotFoundError: No module named 'mo-math'
ModuleNotFoundError: No module named 'mo-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'mo-math' How to remove the ModuleNotFoundError: No module named 'mo-math
ModuleNotFoundError: No module named 'NlpToolkit-Math'
ModuleNotFoundError: No module named 'NlpToolkit-Math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'NlpToolkit-Math' How to remove the ModuleNotFoundError: No module named
ModuleNotFoundError: No module named 'nolimit-math'
ModuleNotFoundError: No module named 'nolimit-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'nolimit-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'pushtogether-math'
ModuleNotFoundError: No module named 'pushtogether-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pushtogether-math' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'pushtogether-math'
ModuleNotFoundError: No module named 'pushtogether-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pushtogether-math' How to remove the ModuleNotFoundError: No module
ModuleNotFoundError: No module named 'pycopy-math'
ModuleNotFoundError: No module named 'pycopy-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pycopy-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'pyUnit-math'
ModuleNotFoundError: No module named 'pyUnit-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pyUnit-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'pyUnit-math'
ModuleNotFoundError: No module named 'pyUnit-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'pyUnit-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'scry-math'
ModuleNotFoundError: No module named 'scry-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'scry-math' How to remove the ModuleNotFoundError: No module named 'scry
ModuleNotFoundError: No module named 'simple_math'
ModuleNotFoundError: No module named 'simple_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'simple_math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'some-math'
ModuleNotFoundError: No module named 'some-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'some-math' How to remove the ModuleNotFoundError: No module named 'some
ModuleNotFoundError: No module named 'some-math'
ModuleNotFoundError: No module named 'some-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'some-math' How to remove the ModuleNotFoundError: No module named 'some
ModuleNotFoundError: No module named 'test-math'
ModuleNotFoundError: No module named 'test-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'test-math' How to remove the ModuleNotFoundError: No module named 'test
ModuleNotFoundError: No module named 'test-math'
ModuleNotFoundError: No module named 'test-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'test-math' How to remove the ModuleNotFoundError: No module named 'test
ModuleNotFoundError: No module named 'tkinter-math'
ModuleNotFoundError: No module named 'tkinter-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'tkinter-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'venkkat_math'
ModuleNotFoundError: No module named 'venkkat_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'venkkat_math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'zqy_math'
ModuleNotFoundError: No module named 'zqy_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'zqy_math' How to remove the ModuleNotFoundError: No module named 'zqy_math
ModuleNotFoundError: No module named 'ancient_math'
ModuleNotFoundError: No module named 'ancient_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ancient_math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'animals-math'
ModuleNotFoundError: No module named 'animals-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'animals-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'baizhan-math'
ModuleNotFoundError: No module named 'baizhan-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'baizhan-math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'blockdiagcontrib-math'
ModuleNotFoundError: No module named 'blockdiagcontrib-math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'blockdiagcontrib-math' How to remove the ModuleNotFoundError
ModuleNotFoundError: No module named 'charc_math'
ModuleNotFoundError: No module named 'charc_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'charc_math' How to remove the ModuleNotFoundError: No module named '
ModuleNotFoundError: No module named 'cjrh_math'
ModuleNotFoundError: No module named 'cjrh_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'cjrh_math' How to remove the ModuleNotFoundError: No module named 'cjrh
ModuleNotFoundError: No module named 'cool_math'
ModuleNotFoundError: No module named 'cool_math'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'cool_math' How to remove the ModuleNotFoundError: No module named 'cool

Ads