0

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 https://stackoverflow.com/search?q=quine

Community
  • 1
  • 1
Ray Lu
  • 26,208
  • 12
  • 60
  • 59
  • Turning this into a community wiki would surely attract more volunteers. – David Hanak Feb 23 '09 at 18:11
  • 1
    Exact duplicate of many, many quine questions on SO: http://stackoverflow.com/search?q=quine – Adam Davis Feb 23 '09 at 18:14
  • No problem. Don't worry about deleting it - it will help others when they try to post the same question by showing up as a suggestion when they enter a new question title. – Adam Davis Feb 23 '09 at 18:16

7 Answers7

12

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

https://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

Community
  • 1
  • 1
Adam Davis
  • 91,931
  • 60
  • 264
  • 330
4

look up Quines.

Ferruccio
  • 98,941
  • 38
  • 226
  • 299
1

You are wanting to read about quines. See here.

ChrisInEdmonton
  • 4,470
  • 5
  • 33
  • 48
1

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

Alex Barrett
  • 16,175
  • 3
  • 52
  • 51
0

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

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

Ben Blank
  • 54,908
  • 28
  • 127
  • 156
Alex Reitbort
  • 13,504
  • 1
  • 40
  • 61
0

Hasn't this question already been asked?

Community
  • 1
  • 1
Zack The Human
  • 8,373
  • 7
  • 39
  • 60
0

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

Milhous
  • 14,473
  • 16
  • 63
  • 82