码迷,mamicode.com
首页 > 其他好文 > 详细

HW4.15

时间:2016-08-14 16:02:48      阅读:133      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8 
 9         System.out.print("Enter n1: ");
10         int n1 = input.nextInt();
11         System.out.print("Enter n2: ");
12         int n2 = input.nextInt();
13 
14         input.close();
15 
16         int greatestCommonDivisor;
17         if(n1 >= n2)
18             greatestCommonDivisor = n2;
19         else
20             greatestCommonDivisor = n1;
21 
22         for(int i = greatestCommonDivisor; i >= 2; i--)
23         {
24             if(n1 % i == 0 && n2 % i == 0)
25             {
26                 greatestCommonDivisor = i;
27                 break;
28             }
29         }
30 
31         System.out.println("The greatest common divisor is " + greatestCommonDivisor);
32     }
33 }

 

HW4.15

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5770198.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!