標(biāo)題:
java歐幾里得算法求最大公約數(shù)
[打印本頁]
作者:
青色的松果
時間:
2022-1-27 17:30
標(biāo)題:
java歐幾里得算法求最大公約數(shù)
public class
Euclid {
public static int
euclid(
int
x,
int
y)
{
int
p = x;
int
q = y;
int
temp =
0
;
while
(q !=
0
)
{ temp = p; p = q; q = temp % q;
System.out.printf(
"p: %d, q: %d
\n
"
, p, q); }
return
p;
}
public static void
main(String[] args){
int
e = euclid(Integer.parseInt(args[
0
]), Integer.parseInt(args[
1
]));
System.out.printf(
"%d
和
%d
的最大公約數(shù)是:
%d
\n
"
, Integer.parseInt(args[
0
]), Integer.parseInt(args[
1
]), e);
}}
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1