Skip to content

Instantly share code, notes, and snippets.

@peter279k
Created May 24, 2017 15:30
Show Gist options
  • Save peter279k/bd118732d53e3ab467d0300f0d3e59fc to your computer and use it in GitHub Desktop.
Save peter279k/bd118732d53e3ab467d0300f0d3e59fc to your computer and use it in GitHub Desktop.
TQC+ JAVA
import java.util.Scanner;
public class JPA03 {
static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args) {
System.out.print("Input m: ");
int m = keyboard.nextInt();
int n = 0;
while(true) {
if(m == 999) {
break;
}
System.out.print("Input n: ");
n = keyboard.nextInt();
if(m < n) {
int temp = m;
m = n;
n = temp;
}
System.out.println("最大公因數為:" + gcdR(m, n));
System.out.print("Input m: ");
m = keyboard.nextInt();
}
}
public static int gcdR(int m, int n) {
if(m % n == 0) {
return n;
}
return gcdR(n, m % n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment