Quine (computing) - Example

Example

The following Java code demonstrates the basic structure of a quine.

public class Quine { public static void main( String args ) { char q = 34; // Quotation mark character String 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 );", " for( int i = 0; i < l.length; i++ ) // Print string array", " System.out.println( l + q + l + q + ',' );", " for( int i = 7; i < l.length; i++ ) // Print this code", " System.out.println( l );", " }", "}", }; for( int i = 0; i < 6; i++ ) // Print opening code System.out.println( l ); for( int i = 0; i < l.length; i++ ) // Print string array System.out.println( l + q + l + q + ',' ); for( int i = 7; i < l.length; i++ ) // Print this code System.out.println( l ); } }

The source code contains a string array of itself, which is output twice, once inside quotation marks.

Read more about this topic:  Quine (computing)

Famous quotes containing the word example:

    Our intellect is not the most subtle, the most powerful, the most appropriate, instrument for revealing the truth. It is life that, little by little, example by example, permits us to see that what is most important to our heart, or to our mind, is learned not by reasoning but through other agencies. Then it is that the intellect, observing their superiority, abdicates its control to them upon reasoned grounds and agrees to become their collaborator and lackey.
    Marcel Proust (1871–1922)