Java program to find hcf of two numbers
Java program to find hcf of two numbers
import java.util.*;
class HCF
{ public static void FindHCF(int x,int y)
{int c=Math.max(x,y);
int d=Math.min(x,y);
while(d!=0)
{int r=c%d;
c=d;
d=r;
}
System.out.println("The HCF of "+x+" and "+y+" :"+c);
}
public static void main()
{Scanner Sc=new Scanner(System.in);
System.out.println("Enter the 1st no. and 2nd ");
int n1=Sc.nextInt();
int n2=Sc.nextInt();
FindHCF(n1,n2);
}
}
Output:-
Enter the 1st no. and 2nd
25
50
The HCF of 25 and 50 :25
Java program to find hcf of two numbers...........................
No comments: