borkins

07. Greatest Common Divisor

Apr 12th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1. /**
  2.  * Project: Advanced_Loops - created by borkins on 2017-04-08.
  3.  */
  4.  
  5. import java.util.Scanner;
  6.  
  7. public class _07_GreatestCommonDivisor
  8. {
  9.     public static int gcd(int a, int b)
  10.     {
  11.         while (a != b)
  12.         {
  13.             if (a > b)
  14.                 a -= b;
  15.             else
  16.                 b -= a;
  17.         }
  18.         return a;
  19.     }
  20.    
  21.     public static void main(String[] args)
  22.     {
  23.         Scanner console = new Scanner(System.in);
  24.        
  25.         int a = Integer.parseInt(console.nextLine());
  26.         int b = Integer.parseInt(console.nextLine());
  27.    
  28.         System.out.println(gcd(a, b));
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment