javaprograms

javaprograms

write GCD program in java

View Answers

September 27, 2011 at 3:19 PM

import java.util.*;

public class GCDOFNumbers {
        public static int gcd(int a, int b) {
                if (b == 0)
                        return a;
                else
                        return gcd(b, a % b);
        }
        public static void main(String[] args){
                Scanner input = new Scanner(System.in);
                System.out.print("Enter Number 1: ");
                int num1 = input.nextInt();
                System.out.print("Enter Number 2: ");
                int num2 = input.nextInt();
                int gcdOfNum = GCDOFNumbers.gcd(num1, num2);
                System.out.println("HCF of two numbers " + num1 + "," + num2+ " is: " + gcdOfNum);
        }
}









Related Tutorials/Questions & Answers:
javaprograms
javaprograms
Advertisements
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms
javaprograms - Java Beginners
javaprograms - Java Beginners
javaprograms - Java Beginners

Ads