2013-03-10 52 views
1

我知道有打印本身就是Quine code
如下面的除了维基百科页面上列出的之外,还有其他Java quines吗?

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

有另一种打印自己的Java程序代码的程序代码?

+3

打印本身的程序按照定义是奎因。 – 2013-03-10 22:38:44

+1

[根据定义](http://en.wikipedia.org/wiki/Quine_(计算)),quine是打印自己的源代码的程序。所以你的字面问题的答案是:不。 – 2013-03-10 22:38:48

+1

每一个turing完整的语言有无限多个quines – Patashu 2013-03-10 23:27:17

回答

4

根据定义,Qu因是一种程序,其输出本身就是。

因此,虽然有许多可能的程序打印自己的来源,而不是您提供的源,但没有任何是而不是奎因。

由于Java是一种图灵完备语言,因此可以使用它编写无限数量的quines(source)。

+0

我认为问题是:那些是什么*许多可能的quines *第二句的第二部分“* there at none ... *“对我没有任何意义 – 2013-03-10 22:44:52

+0

@a_horse_with_no_name,更正了我的答案 – Dancrumb 2013-03-10 23:18:56

相关问题