java 求最大公约数,最小公倍数
利用辗转相除法求两个整数的最大公约数和最小公倍数.注意,这里只写一个方法求最大公约数,最小公倍数放到main方法中完成.
import java.util.Scanner;
public class Chpt7_4 {
public static int fun1(int a1,int b1)
{ int c;
c=a1%b1;
while (c>0)
{a1=b1;
b1=c;
c=a1%b1;
return (b1);
}
}
public static void main(String[] args) {
int a,b,temp;
int m;
Scanner in=new Scanner(System.in);
a=in.nextInt();
b=in.nextInt();
if(a
人气:181 ℃ 时间:2019-10-17 03:22:47
解答
import java.util.Scanner;
public class C{
public static int fun1(int a1,int b1){
int c;
c=a1%b1;
while (c>0)
{a1=b1;
b1=c;
c=a1%b1;
//return b1;
}
return b1; //把return写在这里;
}
public static void main(String[] args) {
int a,b,temp;
int m;
Scanner in=new Scanner(System.in);
a=in.nextInt();
b=in.nextInt();
if(a
推荐
猜你喜欢
- 电阻1的阻值为10,电流表示数为0.8,接入电阻2后,电流表示数为0.2,电源电压与电阻2 的阻值是多少
- 一个圆柱的侧面积是120平方厘米,底面半径是3厘米,这个圆柱的体积是().
- 1.对空发射一物体,不计阻力,当物体速度恰好沿水平时物体炸成a和b两块,若质量较大的a速度放向仍沿原来方向,则
- 以孙晓杰.林雪.做一首爱情诗…
- 有收敛子列的数列是否收敛?
- 问一道英语单选题
- 我要一百道四年级的简算题
- 有机化合物中碳杂化方式