# Math Program

Abhishek Sisodia
Math Program
Posted in : Java Beginners
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.

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

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
Java math class
Java math class  Can you instantiate the Math class
java Math class
java Math class  Why are the methods of the Math class static
Version of com.techshroom>Math dependency
List of Version of com.techshroom>Math dependency
Java math class
Java math class  Why can?t I say just abs() or sin() instead of Math.abs() and Math.sin
Artifacts of commons-math
List of Artifacts of commons-math maven depenency
Math Constants and Functions using JavaScript
Math Constants and Functions using JavaScript  What's Math Constants and Functions using JavaScript
Maven Dependency commons-math >> 1.0
Maven Dependency commons-math >> 1.1
Maven Dependency commons-math >> 20040118.003354
Maven Dependency commons-math >> 20040118.003950
Maven Dependency commons-math >> 20040218.045431
Version of com.cjmalloy>gwt-math dependency
List of Version of com.cjmalloy>gwt-math dependency
Version of com.enterprisemath>em-math dependency
List of Version of com.enterprisemath>em-math dependency
List of Version of com.accelad>nilgiri-math dependency
Version of com.flowpowered>flow-math dependency
List of Version of com.flowpowered>flow-math dependency
Java - Math class in Java
. to manipulate the mathematical operation in your program. The Math class is used... Java - Math class in Java       In this example you will learn about Math class. This example
which part of the cpu does math calculations
which part of the cpu does math calculations  which part of the cpu does math calculations logical calculation
Evaluating a math expression given in string form
Evaluating a math expression given in string form  Evaluating a math expression given in string form
Can you instantiate the Math class? - Java Beginners
Can you instantiate the Math class?   Hi, Can you create object of Math class? Thanks   Hi, All the methods in Math class is static. The constructor is not public in the Math class. So, we can't create
class Math - Java Beginners
its ok?" Complete a program that asks the user a floating-point number (either positive or negative).The program repeats while the user enters 'y'to continue.The program allows the user to enter either a lowercase or uppercse character.Use
Maven Dependency Math >> 1.0.0
List of Version of com.accelad>nilgiri-math-evaluator dependency
Introduction To Math Class In Java
Introduction To Math Class In Java In this tutorial we will read about.... Math class is created inside the java.lang package and the classes created inside... the application. Class Declaration public final class Math extends Object Constant
Maven Dependency nilgiri-math >> 1.10
Maven Dependency nilgiri-math >> 1.11
Maven Dependency nilgiri-math >> 1.12