Skip to content

Instantly share code, notes, and snippets.

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

Embed
What would you like to do?
TQC+ JAVA
import java.util.*;
public class JPA03 {
public static void main (String argv[]) {
int num1, num2;
System.out.println("Input:");
Scanner input = new Scanner(System.in);
num1 = input.nextInt();
while(true) {
if(num1 == 999) {
break;
}
num2 = input.nextInt();
System.out.println(gcd(num1, num2));
System.out.println("Input:");
num1 = input.nextInt();
}
}
static int gcd(int m, int n) {
if(n < m) {
int temp = m;
m = n;
n = temp;
}
while(m % n != 0) {
int temp = m % n;
m = n;
n = temp;
}
return 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.