Question

I know that there is a program code that print itself that is Quine code
As the following

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[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( 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] );
  }
}  

Is there another Java Program code that print itself ?

Was it helpful?

Solution

A Quine is, by definition, a program whose output is itself.

So, while there are numerous possible programs that print their own source other than the one you provided, there at none that are not a quine.

Since Java is a Turing complete language, there are an infinite number of quines that could be written with it (source).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top