题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
1 import java.util.Scanner; 2 3 4 public class Algorithm_Game_06 { 5 public static void main(String[] args) { 6 Scanner s = new Scanner(System.in); 7 int m = s.nextInt(); 8 int n = s.nextInt(); 9 System.out.println("最大公约数:"+f(m, n)); 10 System.out.println("最小公倍数:"+m(m, n)); 11 } 12 public static int f(int m,int n){ 13 int c = m%n; 14 return c==0? n: f(n,c); 15 } 16 public static int m(int m,int n){ 17 return (m*n/f(m,n)); 18 } 19 }