TQC+ JAVA 307 迴圈最大公因數
import java.io.*;
public class JPA03 {
public static void main (String argv[]) throws IOException {
int num1, num2;
BufferedReader buf =new BufferedReader(new InputStreamReader(System.in));
System.out.println("Input:");
num1=Integer.parseInt(buf.readLine());
while (num1!=999) {
num2=Integer.parseInt(buf.readLine());
System.out.println(gcd(num1,num2));
System.out.println("Input:");
num1=Integer.parseInt(buf.readLine());
}
}
static int gcd (int m, int n) {
int result;
while (n!=0){
result=m%n;
m=n;
n=result;
}
return m;
}
}
沒有留言:
張貼留言