Created
May 24, 2017 15:30
-
-
Save peter279k/bd118732d53e3ab467d0300f0d3e59fc to your computer and use it in GitHub Desktop.
TQC+ JAVA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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