Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/purvgwtw/public_html/tutorials/common.php on line 7
Java find HCF of two numbers
Sponsered Links
Categories
Sponsered Links

Java find HCF of two numbers

Here we are going to find the hcf of two numbers.

import java.util.*;
class HCF{
      public static int determineHCF(int a, int b) {
       if (b==0)
       return a;
       else
       return determineHCF(b, a % b);
      }
        public static void main(String[] args)throws Exception {
                HCF cal = new HCF();
                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 hcf = cal.determineHCF(num1, num2);
                System.out.println("HCF of two numbers= "+hcf);
        }
}
 

Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2014 PURVACOMPUTERS.COM All Right Reserved