Sponsered Links
Categories
Sponsered Links

Write a program TO INPUT 2 NO IN THE NAME & PASS THEM TO THE FUNCTIONS. IN THE FUNCTION CAL. HCF & LCM.

Write a program TO INPUT 2 NO IN THE NAME & PASS THEM TO THE FUNCTIONS. IN THE FUNCTION CAL. HCF & LCM.

import java.io.*;

class TEN{
      public static int determineLCM(int a, int b) {
                int num1, num2;
                if (a > b) {
                        num1 = a;
                        num2 = b;
                } else {
                        num1 = b;
                        num2 = a;
                }
                for (int i = 1; i <= num2; i++) {
                        if ((num1 * i) % num2 == 0) {
                                return i * num1;
                        }
                }
                return 0;
        }
       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 {
                TEN cal = new TEN();
                BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("Enter first number: ");
                String input1 = reader.readLine();
                int num1=Integer.parseInt(input1);
                System.out.println("Enter second number: ");
                String input2 = reader.readLine();
                int num2=Integer.parseInt(input2);
                int lcm = cal.determineLCM(num1, num2);
                System.out.println("LCM of two numbers= "+lcm);
                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 © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved