Programming Blog

This blog is about technical and programming questions and there solutions. I also cover programs that were asked in various interviews, it will help you to crack the coding round of various interviews

Friday 30 November 2018

LCM and HCF of two number in java



import java.util.*;

class GFG {
public static void main (String[] args) {

Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    int b = scan.nextInt();
    int c = a,d=b;
    while(a!=b){
 if(a>b)
 a=a-b;
 else
 b=b-a;
 }
 System.out.println("LCM = "+c*d/a);
 System.out.println("HCF = "+a);
}
}

2 comments:

  1. Thanks for sharing your
    knowledge realted to programming

    ReplyDelete
  2. Great work having complete researched material. If you are seeking assignment help services, you can contact team of assignment writers of sourceessay.com anytime. phd thesis croydon

    ReplyDelete