Jump to Real's How-to Main page

Self replicating programs

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));}}
See also this HowTo
If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2007
[ home ]