martinvalchev

Greatest Common Divisor

Nov 21st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GreatestCommonDivisor {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int a = Integer.parseInt(scanner.nextLine());
  7.         int b = Integer.parseInt(scanner.nextLine());
  8.  
  9.         while ( b !=0){
  10.             int temp = b;
  11.             b = a % b;
  12.             a = temp;
  13.  
  14.         }
  15.         System.out.println(a);
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment