Skip to content

Instantly share code, notes, and snippets.

@caseyscarborough
Created April 3, 2014 17:32
Show Gist options
  • Save caseyscarborough/9958958 to your computer and use it in GitHub Desktop.
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.
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