Click here to Skip to main content
15,900,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<pre lang="cs">package bmm2;
import GCD.GCD;
public class Main{
   public static void main(String[] args) {
      long x = Long.parseLong(args[0]);
      long y = Long.parseLong(args[1]);
      long z = GCD.gcd1(x, y);
      System.out.println("Method 1: gcd(" + x + ", " + y + ") = " + z);
           z = GCD.gcd2(x, y);
      System.out.println("Method 2: gcd(" + x + ", " + y + ") = " + z);
   }
}


<pre lang="cs">package GCD;
public class GCD {
   public static long gcd1(long x, long y) {
      if (y == 0) return x;
      return gcd1(y, x % y);
   }
   public static long gcd2(long x, long y) {
      while (y != 0) {
         long r = x % y;
         x = y; y = r;
      }
      return x;
   }
}



it have an error on long x = Long.parseLong(args[0]);????????
Posted
Updated 6-Feb-10 2:07am
v2

1 solution

when you run the program you need to pass two args. I am assuming the code has no errors.

------------

Answer 2

like this
Java Main 1 2
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900