Please write a Java program,compute the GreatestCommonDivisor求JAVA程序

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/30 06:37:10

Please write a Java program,compute the GreatestCommonDivisor求JAVA程序
Please write a Java program,compute the GreatestCommonDivisor
求JAVA程序

Please write a Java program,compute the GreatestCommonDivisor求JAVA程序
// 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}
}