1 package FushiExam; 2 import java.util.*; 3 public class Text_6 { 4 5 public static void main(String[] args) { 6 /* 7 * 输入两个正整数m和n,求其最大公约数和最小公倍数 8 */ 9 Scanner scan=new Scanner(System.in); 10 int a,b; 11 a=scan.nextInt(); 12 b=scan.nextInt(); 13 exchange(a,b); 14 int c=max(a,b);//最大公约数 15 System.out.println("最大公约数是:"+c); 16 System.out.println("最小公倍数是:"+(a*b/c)); 17 18 19 } 20 public static void exchange(int a,int b) { 21 if(a<b) { 22 int t=b; 23 b=a; 24 a=t; 25 } 26 } 27 public static int max(int a,int b) { 28 int r=a%b; 29 while(r!=0) { 30 a=b; 31 b=r; 32 r=a%b; 33 } 34 return b; 35 } 36 37 }
JAVA编程---------6、最大公约数和最小公倍数
猜你喜欢
转载自www.cnblogs.com/fmust/p/12450405.html
今日推荐
周排行