class Euclid { public static int gcd(int x, int y) { if(x < y) { int temp = x; x = y; y = temp; } while((x%y) != 0) { int rem = x%y; x = y; y = rem; } return y; } // End gcd() public static void printDigits(int x) { if(x <= 0) { System.out.println("I don't know how to handle x<=0"); return; } int oldx = x; // Loop for calculating number of digits int pow10 = 1; int numDigits = 0; while(x > 0) { x = x/10; numDigits++; pow10 *= 10; } x = oldx; // Loop for printing digits while(pow10 != 1) { pow10 = pow10/10; System.out.print(x/pow10); x = x%pow10; } System.out.println(); } // End printDigits() public static void main(String[] args) { System.out.println("gcd of 100 and 36 is " + gcd(100, 36)); System.out.println("gcd of 625 and 100 is " + gcd(625, 100)); System.out.println("gcd of 625 and 104 is " + gcd(625, 104)); System.out.println("gcd of 104 and 104 is " + gcd(104, 104)); printDigits(203); } } // End class Euclid