-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcd.java
More file actions
32 lines (22 loc) · 652 Bytes
/
gcd.java
File metadata and controls
32 lines (22 loc) · 652 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
public class gcd{
public static void main(String[]args){
Scanner inp= new Scanner(System.in);
System.out.println("This is a program that helps to find GCD.");
boolean quit=false;
while(true){
int gcd=1, i=1;
System.out.println("Type in two integers to find their greatest common divisor: ");
int n1=inp.nextInt();
int n2=inp.nextInt();
do{
if(n1%i==0 && n2%i==0)
gcd=i;
i++;
}while(i<=n1 && i<=n2);
System.out.println("GCD of "+n1+" and "+n2+" is "+ gcd+".");
}
System.out.println("Type \"quit\" to quit the GCD calculator, otherwise the program will continue on.");
String quitornot=inp.nextLine();
}//main
}//class