源程序:
import java.lang.* ;
public class Test{
public static void main(String[] args){
int m = (int)( Math.random() * 1000 ) ;
int n = (int)( Math.random() * 1000 ) ;
System.out.println() ;
System.out.println("m = " + m + " n = " + n) ;
int t = 0 ;
int r = m < n ? m : n ;
do{
if(m % (r - 1) == 0){
t = r - 1 ;
}
r -- ;
}
while(r != 2&& r != 1) ;
System.out.println() ;
System.out.println(m + "和" + n + "的最大公约数为: " + t ) ;
}
}
运行结果: