自产生程序

来源:互联网 发布:网络侦探 2周目 彩蛋 编辑:程序博客网 时间:2024/05/16 01:36

本博客转自:https://originals-tz.github.io/

自产生程序(Quine),它以哲学家奎恩命名

指的是输出结果为程序自身源码的程序。

能够直接读取自己源码、读入用户输入或空白的程序一般都不视为自产生程序。

java 实现

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]);  }}
原创粉丝点击