java中题目:输入两个正整数m和n,求其最大公约数和最小公倍数。

13.题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
最大公约数:使用辗转相除法
最小公倍数=两个正整数相乘除以最大公约数
图片来源与百度百科
tup

/**
 * 
 */
package com.gem.demo.day03_practice;

import java.util.Scanner;

/**
 *
 * Description:13.题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
 * 辗转相除法求最大公约数
 * 最小公倍数=两个数相乘除以最大公约数。
 *
 * @author HadwinLing
 *
 * @date 2020年1月10日下午7:49:33
 *
 * @version 0.0.1 
 *
 */
public class practice13 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		System.out.println("请输入一个数");
		int num1 = input.nextInt();
		System.out.println("请输入一个数");
		int num2 = input.nextInt();
		int max = max(num1,num2);
		System.out.println("max="+max);
		System.out.println("min="+(num1*num2/max));
	}
	public static int max(int a,int b) {
		int temp;
		if(a<b) {
			temp=b;
			b=a; 
			a=temp;
		}
		int Remainder ;//余数
		while((Remainder=a%b)!=0) {
			a=b;
			b = a%b;
		}
		return b;
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值