A quine is a program that prints itself:
Quine in JS
// browser
!function $(){console.log('!'+$+'()')}()
// node
(function quine() {
console.log(quine.toString())
})()
Quine in Java
// http://c2.com/cgi/wiki?QuineProgram
public class Quine {
public static void main(String[] args) {
String[] str = {
"public class Quine {",
" public static void main(String[] args) {",
" String[] str = {",
" };",
" for(int i=0;i<3;i++)System.out.println(str[i]);",
" for(int i=0;i<9;i++)System.out.println((char)34+str[i]+(char)34+',');",
" for(int i=3;i<9;i++)System.out.println(str[i]);",
" }",
"}",
};
for(int i=0;i<3;i++)System.out.println(str[i]);
for(int i=0;i<9;i++)System.out.println((char)34+str[i]+(char)34+',');
for(int i=3;i<9;i++)System.out.println(str[i]);
}
}
Practical use
I used quines to print my programs as slides during Functional Programming workshop.
Brak komentarzy:
Prześlij komentarz