Program to find HCF/GCD | Java

preview_player
Показать описание


My other videos-
Рекомендации по теме
Комментарии
Автор

Wonderful explanation sir. Especially your handwriting is so clear and visible. Thanks for this video sir. Please keep uploading videos sir.

vinethasuresh
Автор

Understanding the concepts clearly please keep uploading videos

sindhuhari
Автор

Multidimensional Array concepts please

sahityasahi
Автор

the concept is very helpful Do programs on second largest number in array

mohammedasif
Автор

wrong method you have taken fixed values which give a and b become same what if a is 42 b is 16

bpsaikrishnareddy
Автор

import java.util.Scanner;

public class GCD {

public static void main(String[] args) {
Scanner scan =new Scanner(System.in);
System.out.println("enter first number");
int n1 =scan.nextInt();
System.out.println("enter second number :");
int n2=scan.nextInt();

if(n1==0) {
System.out.println("GCD is: "+n2);

}
else if(n2==0) {
System.out.println("GCD is :"+n1);
}

while(n1!=n2) {
if(n1>n2)
{
n1=n1-n2;
}
if(n1<n2) {
n2=n2-n1;
}
}
if(n1==n2) {
System.out.println("GCD of n1 and n2 is : " +n1);
}
}
}
here is the correct format of the code

morbiusff
Автор

Bro you declared String but you stored integer . please first learn then teach ..

BanglaWaz-
Автор

superb logic, but is it suggestable to be written in board exam?

deathknight