Advertisement
Flaron

Udemy_20. GreatestCommonDivider

Sep 14th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. package lista.Alapok;
  2.  
  3. public class Main {
  4.  
  5. public static int getGreatestCommonDivisor(int first, int second) {
  6. if(first<10 || second<10) return -1;
  7. int count=0;
  8.  
  9. for (int i = 1; i <=first && i<=second ; i++) {
  10. if (first%i==0 && second%i==0)
  11. count=i;
  12. } return count;
  13. }
  14.  
  15. public static void main(String[] args) {
  16. System.out.println(getGreatestCommonDivisor(12, 30));
  17. }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement