views:

393

answers:

7

How many ways are there to let the code output itself?

For example, write the code below,

public class Test
{
   public static void main(String[] args)
   {
      // some code
   }
}

to output itself

public class Test
{
   public static void main(String[] args)
   {
      // some code
   }
}

(Any programming language is accepted)

EDIT This question has been answered in the historical posts, search "quine" or check out http://stackoverflow.com/search?q=quine

+4  A: 

look up Quines.

Ferruccio
+11  A: 

This is called a programming quine, and has been extensively discussed on SO:

http://stackoverflow.com/search?q=quine

Also see

http://en.wikipedia.org/wiki/Quine_(computing)

http://www.nyx.net/~gthompso/quine.htm

http://www.madore.org/~david/computers/quine.html

Adam Davis
+1  A: 

You are wanting to read about quines. See here.

ChrisInEdmonton
A: 

Hasn't this question already been asked?

Zack Mulgrew
A: 

There are an infinite number ways to do this. All you have to do is find one way and then add comments....

Milhous