Ein selbst-druckendes Programm

Wie funktioniert das? (Was steht in int [] [] a?)

class Self {
    public static void main (String [] args) {
int [] [] a = { { 9, 83, 121, 115, ... }, ... };
        System.out.println ("class Self {");
        System.out.println ("    public static void main (String [] args) {");
        System.out.print ("int [] [] a = ");
        for (int i = 0; i < a.length; i++) {
            String isep = (0 == i) ? "{ " : ", ";
            System.out.print (isep);
            for (int j = 0; j < a[i].length; j++) {
                String jsep = (0 == j) ? "{ " : ", ";
                System.out.print (jsep + a[i][j]);
            }
            System.out.println (" }");
        }
        System.out.println ("};");
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[i].length; j++) {
                System.out.print ((char) a[i][j]);
            }
            System.out.println ();
        }
    }
}

kompletter Quelltext hier: http://www.imn.htwk-leipzig.de/~waldmann/edu/current/informatik/programme/self/Self.java

Finden Sie kürzere selbstdruckende Programme? (google: self printing program)



Johannes Waldmann 2007-06-04