JAVA Program to Find GCD of Two Numbers

JAVA Program to Find GCD of Two Numbers:


import java.io.*;
class gcd
{
 public static void main(String args[])
  {
   int a,b;
   a= Integer.parseInt(args[0]);
   b= Integer.parseInt(args[1]);
   System.out.println("a= "+a);
   System.out.println("b= "+b);
   while ( a!=b)
   {
    if(a>b)
     a=a-b;
     else
     b=b-a;
   }
   System.out.println("GCD = "+ a);
   }
 }

OUTPUT:

a= 8
b= 32
GCD = 8

Leave a Reply

Your email address will not be published. Required fields are marked *

4 × four =

This site uses Akismet to reduce spam. Learn how your comment data is processed.