fork download
  1. public class Main {
  2.  
  3. // ideone doesn't support cmd args
  4. static final String[] ARGS = {"24", "18"};
  5.  
  6. public static void main (String[] args) {
  7. int a = Integer.parseInt(ARGS[0]);
  8. int b = Integer.parseInt(ARGS[1]);
  9. System.out.printf("GCD of %d and %d: %d%n", a, b, gcd(a, b));
  10. }
  11.  
  12. public static int gcd(int a, int b) {
  13. if (b > a) return gcd(b, a);
  14. else if (b == 0) return a;
  15. else if (a == 0) return b;
  16. else return gcd(b, a%b);
  17. }
  18. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
GCD of 24 and 18: 6