- import java.util.Scanner;
- public class JPD04 {
- static Scanner keyboard = new Scanner(System.in);
- public static void main(String args[]) {
-
- int m,n;
- System.out.println("Input m:");
- m = keyboard.nextInt();
- while(m!=999)
- {
- System.out.println("Input n:");
- n = keyboard.nextInt();
- System.out.println("最大公因數為:"+gcd(m,n));
- System.out.println("Input m:");
- m = keyboard.nextInt();
- }
-
- }
-
- static int gcd(int m,int n)
- {
- if(m%n ==0)
- {
- return n;
- }
- else
- {
- return gcd(n,m%n);
- }
- }
-
-
- }
複製代碼 |