Self replicating programsTag(s): Varia


A self replicating programs (also known as Quine) is computer program which prints its own listing!

Try these and try to explain the output!

First example

class S{public static void main(String[]a){char c=34;String s=
"class S{public static void main(String[]a){char c=34;String s=;"+
"System.out.println(s.substring(0,62)+c+s+c+s.substring(62));}}";
System.out.println(s.substring(0,62)+c+s+c+s.substring(62));}}

Second example

class a{public static void main(String x[]){String []s=
{"class a{2}public static void main(String x[]){2}String"+
"[]s={2}{1}{0}{1};new String(new char[]{2}34}),new String"+
"(new char[]{2}123});System.out.println(java.text.MessageFormat"+
".format(s[0],s));}}",new String(new char[]{34}),
new String(new char[]{123})};
System.out.println(java.text.MessageFormat.format(s[0],s));}}

Third example
author Daniel Pitts

[Q.java]

enum Q {a("enum Q{a(%c%s%c);Q(String t){System.out.printf(t,34,t,34);System.exit(0);}}");
Q(String t){System.out.printf(t,34,t,34);System.exit(0);}}

See also this HowTo

blog comments powered by Disqus