Chapter: Miscellaneous Last Updated: 29-08-2017 14:44:59 UTC

Program:

` ````
/* ............... START ............... */
public class JavaGCDOfTwoNumbers {
public static void main(String[] args) {
int n1 = 81, n2 = 153, gcd = 1;
for (int i = 1; i <= n1 && i <= n2; ++i) {
// Checks if i is factor of both integers
if (n1 % i == 0 && n2 % i == 0)
gcd = i;
}
System.out.printf("G.C.D of %d and %d is %d", n1, n2, gcd);
}
}
/* ............... END ............... */
```

Output

G.C.D of 81 and 153 is 9

Notes:

- The Fibonacci series is a series where the next term is the sum of pervious two terms. The first two terms of the Fibonacci sequence is 0 followed by 1.
- The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

Tags

Find GCD Of Two Numbers, Java, Miscellaneous