作业帮 > 综合 > 作业

Please write a Java program,compute the GreatestCommonDiviso

来源:学生作业帮 编辑:搜狗做题网作业帮 分类:综合作业 时间:2024/06/13 14:13:34
Please write a Java program,compute the GreatestCommonDivisor
求JAVA程序
Please write a Java program,compute the GreatestCommonDiviso
// m,n > 0
public class Test {
\x05public static void main(String[] args){
\x05\x05Test t = new Test();\x05\x05
\x05\x05System.out.println(t.getGreatestCommonDivisor(36,8));\x05\x05
\x05}
\x05public int getGreatestCommonDivisor(int m,int n) {
\x05 if(m < n) {
\x05 int temp = 0;
\x05 temp = m;
\x05 m = n;
\x05 n = temp;
\x05 }
\x05 int r = m % n;
\x05 while(r != 0){
\x05 m = n;
\x05 n = r;
\x05 r = m % n;
\x05 }
\x05 return n;
\x05}
}