Math Program

Ads

 
 

Share on Google+Share on Google+

Abhishek Sisodia
Math Program
1 Answer(s)      7 years ago
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.
Ads
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

Ads









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
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
You should include the dependency code given in this page to add Maven Dependency of commons-math >> commons-math version1.0 in your project
Maven Dependency commons-math >> 1.1
You should include the dependency code given in this page to add Maven Dependency of commons-math >> commons-math version1.1 in your project
Maven Dependency commons-math >> 20040118.003354
You should include the dependency code given in this page to add Maven Dependency of commons-math >> commons-math version20040118.003354 in your project
Maven Dependency commons-math >> 20040118.003950
You should include the dependency code given in this page to add Maven Dependency of commons-math >> commons-math version20040118.003950 in your project
Maven Dependency commons-math >> 20040218.045431
You should include the dependency code given in this page to add Maven Dependency of commons-math >> commons-math version20040218.045431 in your project
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
Version of com.accelad>nilgiri-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
You should include the dependency code given in this page to add Maven Dependency of com.techshroom >> Math version1.0.0 in your project
Version of com.accelad>nilgiri-math-evaluator dependency
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
You should include the dependency code given in this page to add Maven Dependency of com.accelad >> nilgiri-math version1.10 in your project
Maven Dependency nilgiri-math >> 1.11
You should include the dependency code given in this page to add Maven Dependency of com.accelad >> nilgiri-math version1.11 in your project
Maven Dependency nilgiri-math >> 1.12
You should include the dependency code given in this page to add Maven Dependency of com.accelad >> nilgiri-math version1.12 in your project
Maven Dependency nilgiri-math >> 1.13
You should include the dependency code given in this page to add Maven Dependency of com.accelad >> nilgiri-math version1.13 in your project
Maven Dependency nilgiri-math >> 1.14
You should include the dependency code given in this page to add Maven Dependency of com.accelad >> nilgiri-math version1.14 in your project
Maven Dependency nilgiri-math >> 1.15
You should include the dependency code given in this page to add Maven Dependency of com.accelad >> nilgiri-math version1.15 in your project

Ads

 
Advertisement null

Ads