Why So Scared

A blog about; Programming, Music and Random Stuff

Java Greatest Common Divisor – Method

1
2
3
4
5
6
7
8
9
10
11
12
13
public class cis229wk3 {
	 static long gcd(long m, long n) {
		   if (n==0)
		     return m;
		   else
		     return gcd(n, m % n);
	} 

	public static void main(String [] args) {
		System.out.println(gcd(4,8));
		// program returns a 4
	}
}
posted by Juo in Java and have No Comments

Place your comment

Please fill your data and comment below.
Name
Email
Website
Your comment