Define a method to find the maximum common divisor of two integers

import java. util. Scanner; /* * Define a method to find the maximum common divisor of two integers * / public class demp29 {public static void main (string [] args) {scanner SC = new scanner (system. In); system.out.println ("please enter two positive integers:"); int x = sc.nextint(); int y = sc.nextint(); system.out.println (the maximum common divisor of X + "and" + y + "is:" + getgcd (x, y));} public static int getGCD(int m,int n) { for(int x=m;x>=1;x--) { if(m%x==0&&n%x==0) return x; } return 1; } }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>