首页 > 其他 > 详细

第二实验第三个作业

时间:2016-04-15 00:15:04      阅读:165      评论:0      收藏:0      [点我收藏+]

import java.util.Scanner;

public class demo {

/**
* @param args
* 3137102219
* 余义铭
*/
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
System.out.println("请输入两个整数:");
int a=0;
int b=0;
try
{
a=s.nextInt ();
b=s.nextInt();
}
catch (Exception e)
{
// TODO: handle exception
System.out.println("无公约数!");
}
MaxDivisor m=new MaxDivisor(a,b);
}
}

public class MaxDivisor{
int A;
int B;
int res;

public MaxDivisor(int a,int b){
if(a>0 && b>0)
{
A=a;
B=b;
res = A % B;
}
while(res!=0)
{
A=B;
B=res;
res=A % B;
}

System.out.println(B);
}

}

第二实验第三个作业

原文:http://www.cnblogs.com/jiujienaxin/p/5393324.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!