Skip to content

Instantly share code, notes, and snippets.

@peter279k peter279k/JPA04.java
Created May 24, 2017

Embed
What would you like to do?
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
You can’t perform that action at this time.