/** * @author monika heiner * @version 1.0 * @date 23.04.2012 * @class ProcDemo3Euklid */ import java.util.Scanner; class ProcDemo3Euklid { // GgT zweier Zahlen nach Euclid mit // mit parameterisierter Prozedur public static void main(String[] args) { // Vereinbarungen Scanner in = new Scanner(System.in); int a, b; // Eingabe System.out.println("EUCLID freut sich auf Ihre Anfrage!"); System.out.print(" Eingabe der ersten ganzen Zahl: "); a = in.nextInt(); System.out.print(" Eingabe der zweiten ganzen Zahl: "); b = in.nextInt(); // es werden vernünftige Werte für a und b unterstellt. // Verarbeitung int ergebnis = euklid(a,b); // Ausgabe System.out.println("EUCLID: \"GgT von "+a+" und "+b+" ist "+ ergebnis +".\""); } // main // Euklidsche Algorithmus static int euklid (int fa, int fb) { int z1, z2, rest; if (fa > fb) { z1 = fa; z2 = fb; } else { z2 = fa; z1 = fb; } // if rest = z1 % z2; while (rest != 0) { z1 = z2; z2 = rest; rest = z1 % z2; } // while return z2; } // euklid } // ProcDemo3Euklid