[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 187
  • Last Modified:

gcd

I need help writing d gcd method, can someone give me some hints?  here is what i got so far:

**********************

public abstract int gcd (int a, int b) {
      
            if  (a == 0) {
                  gcd = 0;
            }
            else if ( (a % b) == 0) {
                  gcd = b;      
            }
            else if ( (a/b) == (1/2)) {
                  gcd = a;
            }
            
            
                  return gcd;
                  System.out.println (gcd);
0
debby76
Asked:
debby76
1 Solution
 
_lychee_Commented:
that's not gcd.... and at any rate, gcd is not defined, and u'll never print the gcd... i assume this is java...
here's something: i assume a<b...

class Gcd {
   public static int gcd(int a, int b) {
      if (a==0) return b;
      return gcd(b%a, a);
   }

   public static void main(String[] arg) {
      System.out.println(gcd(3, 7));
   }
}

this should work
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now