求助:求45 和60的最大公约数的程序怎么写啊
#@#$^% #@#$^% 这个程序不会写,好心的蝈蝈们麻烦会的写下。#@#$@! 先谢谢了我也是刚学,笨方法,不通用
public class gys {public static void main(String []args){
int a = 45,b = 60,x,i;
x = b % a;
i = a % x;
if (i == 0){
System.out.println("45和60的最大公約数是"+x);
}
}
}
你试试
public class numSort {/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int a=45;
int b=60;
int c;
int d;
for(int i=45;i>1;i--){
if(b%i==0&&a%i==0){
c=i;
System.out.println("最大公约数:"+c);
break;
}
else{
}
}
for(int j=60;j<=(60*45);j++)
if(j%60==0&&j%45==0){
d=j;
System.out.println("最小公倍数:"+d);
break;
}
else{
}
}
}
页:
[1]
