我知道有一个打印自身的程序代码是奎因代码
如下
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 程序代码可以打印自己?
最佳答案
根据定义,Quine 是一个程序,其输出是它本身。
因此,虽然有许多可能的程序打印它们自己的源而不是您提供的源,但没有一个不是一个问题。
由于 Java 是一种图灵完备的语言,因此可以用它编写无限多的 quines ( source )。
关于java - 除了维基百科页面上列出的那个,还有其他 Java quines 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15328568/