daily pastebin goal
47%
SHARE
TWEET

Untitled

a guest Mar 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package greatestcommondivisor;
  7.  
  8. import java.util.*;
  9.  
  10. public class GreatestCommonDivisor {    
  11.    
  12.     static Scanner input = new Scanner(System.in);
  13.     static ArrayList<Integer> list = new ArrayList<Integer>();
  14.    
  15.     public static int divisorCalc(int num1, int num2, int divisor) {
  16.        
  17.         if (num1 == divisor || num2 == divisor) return(0);
  18.        
  19.         if ((num1 % divisor == 0) && (num2 % divisor == 0)) {
  20.             list.add(divisor);
  21.             return divisorCalc(num1, num2, divisor + 1);
  22.         }
  23.         else {
  24.             return 0;
  25.         }
  26.        
  27.     }
  28.    
  29.     public static void main(String[] args) {
  30.        
  31.         int divisorMain = 1;
  32.         System.out.println("Input 2 Positive Numbers");
  33.         int digitOne = input.nextInt();
  34.         int digitTwo = input.nextInt();
  35.         divisorCalc(digitOne, digitTwo, divisorMain);
  36.        
  37.         System.out.println(list);
  38.        
  39.     }
  40.     // Recursively count up by 1 and divide the two numbers, if the remainder equals zero, store it to an array and once finished take the largest number from that array.
  41. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top