Today see a very interesting question, how to output a program of their own source code, see the first response to this problem is naturally read the source file, and then output line by row.
However, if you add a restriction, you cannot read the file.
Emmm ... After thinking for a long time, the wiki rescued me, and the following was excerpted from the wiki. First on the source code.
Public classquine{ Public Static voidMain (string[] args) {CharQ = 34;//quotation mark characterString[] L = {//Array of source code"Public class Quine", "{", "public static void Main (string[] args)", " {", "Char q = 34; Quotation mark character ", "string[] L = {//Array of source code", " ", " };", "For" (int i = 0; I < 6; i++)//Print Opening code ", "System.out.println (L[i]);", "For" (int i = 0; i < l.length; i++)//Print string array ", "System.out.println (L[6] + q + l[i] + q + ', ');", "For" (int i = 7; i < l.length; i++)//Print This Code ", "System.out.println (L[i]);", " }", "}", }; for(inti = 0; I < 6; i++)//Print Opening CodeSystem.out.println (L[i]); for(inti = 0; i < l.length; i++)//Print string ArraySystem.out.println (L[6] + q + l[i] + q + ', '); for(inti = 7; i < l.length; i++)//Print This codeSystem.out.println (L[i]); }}
The first half of the program is the Java run must prefix, and then add a variable Q (the content is quoted ""), the middle part of a string array to record the entire program source code (including the output source), the latter part is used to output the source code. Emm Anyway read this code, feel enlightened, this blog is not a technical blog, just to Quine do a record, if you see this blog on other languages how to achieve quine curious can see https://en.m.wikipedia.org/wiki/ Quine_ (computing), the source code is also on the wiki.
The following source code is on the basis of Quine, slightly modified a little bit of Java source code in the package also output implementation. (actually did not change what, main or Quine's realization is 2333).
PackageXJBG; Public classquine{ Public Static voidMain (string[] args) {CharQ = 34;//quotation mark characterString[] L = {//Array of source code"Package XJBG;", "", "Public class Quine", "{", "public static void Main (string[] args)", " {", "Char q = 34; Quotation mark character ", "string[] L = {//Array of source code", " ", " };", "For" (int i = 0; I < 8; i++)//Print Opening code ", "System.out.println (L[i]);", "For" (int i = 0; i < l.length; i++)//Print string array ", "System.out.println (L[8] + q + l[i] + q + ', ');", "For" (int i = 9; i < l.length; i++)//Print This Code ", "System.out.println (L[i]);", " }", "}", }; for(inti = 0; I < 8; i++)//Print Opening CodeSystem.out.println (L[i]); for(inti = 0; i < l.length; i++)//Print string ArraySystem.out.println (L[8] + q + l[i] + q + ', '); for(inti = 9; i < l.length; i++)//Print This codeSystem.out.println (L[i]); }}
If there is an import can also be added to the beginning of the array, then this record blog to this end!
quine--Output Program source code program (Java)