Created
April 3, 2014 17:32
-
-
Save caseyscarborough/9958958 to your computer and use it in GitHub Desktop.
A quine, a program that emits takes in no input and outputs it's own source code, written in Java.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Quine { | |
static String[] lines = { | |
"public class Quine {", | |
" static String[] lines = {", | |
" };", | |
" static String source(String[] lines) {", | |
" char q = (char) 34;", | |
" char nl = (char) 10;", | |
" int edge = 2;", | |
" int count = 24;", | |
" StringBuffer buff = new StringBuffer();", | |
" for (int i = 0; i < edge; i++) {", | |
" buff.append(lines[i]).append(nl);", | |
" }", | |
" for (int i = 0; i < count; i++) {", | |
" buff.append(q + lines[i] + q + ',').append(nl);", | |
" }", | |
" for (int i = edge; i < count; i++) {", | |
" buff.append(lines[i]).append(nl);", | |
" }", | |
" return buff.toString().trim();", | |
" }", | |
" public static void main(String[] args) {", | |
" System.out.println(source(lines));", | |
" }", | |
"}", | |
}; | |
static String source(String[] lines) { | |
char q = (char) 34; | |
char nl = (char) 10; | |
int edge = 2; | |
int count = 24; | |
StringBuffer buff = new StringBuffer(); | |
for (int i = 0; i < edge; i++) { | |
buff.append(lines[i]).append(nl); | |
} | |
for (int i = 0; i < count; i++) { | |
buff.append(q + lines[i] + q + ',').append(nl); | |
} | |
for (int i = edge; i < count; i++) { | |
buff.append(lines[i]).append(nl); | |
} | |
return buff.toString().trim(); | |
} | |
public static void main(String[] args) { | |
System.out.println(source(lines)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment