Please write a Java program,compute the GreatestCommonDiviso

学习 时间:2026-03-30 15:03:41 阅读:6513
Please write a Java program,compute the GreatestCommonDivisor求JAVA程序

最佳回答

过时的蜜蜂

火星上的发箍

2026-03-30 15:03:41

// m,n > 0public 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}}

最新回答共有2条回答

  • 火星上的鸵鸟
    回复
    2026-03-30 15:03:41

    // m,n > 0public 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}}

上一篇 英语翻译电梯(电梯型号:)电梯部件国产化(Team Leader)主要负责:新供应商资源查找、筛选;供应商考察、评估;产

下一篇 上偏差es与下偏差ei中的英文单词是什么