Hi,
wir sollen für den modernen und klassischen euklidischen Algorithmus eine Trace Tabelle erstellen, ich habe auch eine gute Idee wie ich das ungefähr mit Ausgabenanweisungen anstellen kann, aber leider ergibt meine Ausgabe am Ende nicht wirklich Sinn.
Ich wäre um jeglichen Tipp dankbar
LG
wir sollen für den modernen und klassischen euklidischen Algorithmus eine Trace Tabelle erstellen, ich habe auch eine gute Idee wie ich das ungefähr mit Ausgabenanweisungen anstellen kann, aber leider ergibt meine Ausgabe am Ende nicht wirklich Sinn.
Ich wäre um jeglichen Tipp dankbar
LG
Java:
public class EuklidKlassisch {
public static void main( String[] args ){
int x = Integer.parseInt(args[0]); // Wertuebernahme von ...
int y = Integer.parseInt(args[1]); // ... der Kommandozeile
if ( x <= 0 || y <= 0) { // '||' steht fuer 'oder'
System.out.println("nur positive Argumente!!");
return; // Ende
}
System.out.println("| line| x | y | comment" );
// ggT(x,y) // K1
System.out.println("| K1 | " + x +" | " + y +" | ggt(" + x + "," + y + ")" );
while ( y != 0 ) { // K2
System.out.println("| K2 | " + x +" | " + y +" | while(" + y + " != 0)");
if ( x > y ) { // K3
System.out.println("| K3 | " + x +" | " + y +" | if (" + x + " > "+ y );
x = x - y; // K4
System.out.println("| K4 | " + x +" | " + y +" | x = "+ x + " - "+ y );
} else {
y = y - x; // K5
System.out.println("| K5 | " + x +" | " + y +" | y = "+ y + " - "+ x );
}
}
System.out.println("| K6 | " + x +" | " + y +" | = "+ x );
return;
}
}