fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int a = (int) (Math.random()*200);
  13. int b= (int) (Math.random()*20);
  14. System.out.println("When a is " +a+ " and b is " +b+ ",");
  15. if (gcd(a,b)==1)
  16. {
  17. System.out.println("The Greatest Common Denominator of" +a+ " and " +b+ " is " +gcd(a,b)+ " so one number must be prime.");
  18. }
  19. System.out.println("The Greatest Common Denominator of " +a+ " and " +b+ " is " +gcd(a,b)+ ".");
  20. }
  21.  
  22. public static int gcd(int a, int b)
  23. {
  24. int m = a, n = b; // never modify params
  25. while (m != n)
  26. {
  27. if (m > n)
  28. { m = m-n;}
  29. else
  30. {n = n - m;}
  31. }
  32. return m;
  33. }
  34.  
  35. }
Success #stdin #stdout 0.06s 380224KB
stdin
Standard input is empty
stdout
When a is 117 and b is 17,
The Greatest Common Denominator of117 and 17 is 1 so one number must be prime.
The Greatest Common Denominator of 117 and 17 is 1.