write GCD program in java
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); } }
Ads