public class GGTTable extends MiniJava { public static void main(String[] args) { int x = -1; while (x <= 0) { x = read("Wie groß soll die GGT-Tabelle sein? " + "Bitte eine positive Zahl eingeben"); } System.out.println(ggTTable(x)); } public static String ggTTable(int size) { String table = ""; // Überschriftenzeile int header = 1; while (header <= size) { table += "\t" + header; header++; } table += "\n"; // Headerzeile abschließen // Inhalt und Zeilennummern int row = 1; while (row <= size) { table = table + row; int column = 1; while (column <= size) { table += "\t" + ggT(row, column); column++; } table += "\n"; row++; } return table; } // für Zahlen >= 0 public static int ggT(int a, int b) { if (a == 0) return b; if (b == 0) return a; while (a != b) { if (a < b) b -= a; else // a > b a -= b; } return a; } }