Computer Science, asked by mehuleedas, 6 months ago

Write a Java Programming:-

Input 2 numbers and print HCF of two numbers. ​

Answers

Answered by kaursandeep86563
0

Answer:

Define two variables - A, B.

Set loop from 1 to max of A, B.

Check if both are completely divided by same loop number, if yes, store it.

Display the stored number is HCF.

Answered by jisoo86
4

Explanation:

import java.util.Scanner;

public class GCDOfTwoNumbers {

public static void main(String args[]){

int a, b, i, hcf = 0;

Scanner sc = new Scanner(System.in);

System.out.println("Enter first number :: ");

a = sc.nextInt();

System.out.println("Enter second number :: ");

b = sc.nextInt();

for(i = 1; i <= a || i <= b; i++) {

if( a%i == 0 && b%i == 0 )

hcf = i;

}

System.out.println("HCF of given two numbers is ::"+hcf);

}

}

output:-Enter first number ::

625

Enter second number ::

125

HCF of given two numbers is ::125

Similar questions