Write a program in java to find the highest common factor(HCF)
import java.io.*;
class hcf
{
public static void main(String [] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int h=0;
int x=Integer.parseInt(br.readLine());
int y=Integer.parseInt(br.readLine());
int c=x*y;
for (int a=1;a<=c;a++)
if ((x%a)==0 && (y%a)==0)
h = a;
System.out.println(h);
}
}
ANY QUERY COMMENT BELOW:---
class hcf
{
public static void main(String [] args)throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int h=0;
int x=Integer.parseInt(br.readLine());
int y=Integer.parseInt(br.readLine());
int c=x*y;
for (int a=1;a<=c;a++)
if ((x%a)==0 && (y%a)==0)
h = a;
System.out.println(h);
}
}
ANY QUERY COMMENT BELOW:---
Post a Comment