Created
April 13, 2010 14:23
-
-
Save Ming-Tang/364684 to your computer and use it in GitHub Desktop.
This file contains 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
import java.io.*;import javax.tools.*;class Quine1{static final char Q=34;static final int N=1;public static void main(String[]a)throws Exception{System.out.println("This is the program "+N);String fn="Quine"+(N+1)+".java";BufferedWriter out=new BufferedWriter(new FileWriter(fn));String s="import java.io.*;import javax.tools.*;class Quine%d{static final char Q=34;static final int N=%d;public static void main(String[]a)throws Exception{System.out.println(%cThis is the program %c+N);String fn=%cQuine%c+(N+1)+%c.java%c;BufferedWriter out=new BufferedWriter(new FileWriter(fn));String s=%c%s%c;out.write(String.format(s,N+1,N+1,Q,Q,Q,Q,Q,Q,Q,s,Q,Q,Q,Q,Q));out.close();JavaCompiler c=ToolProvider.getSystemJavaCompiler();c.run(null,null,null,fn);Class.forName(%cQuine%c+(N+1)).getMethod(%cmain%c,a.getClass()).invoke(null,new Object[]{new String[]{}});}}";out.write(String.format(s,N+1,N+1,Q,Q,Q,Q,Q,Q,Q,s,Q,Q,Q,Q,Q));out.close();JavaCompiler c=ToolProvider.getSystemJavaCompiler();c.run(null,null,null,fn);Class.forName("Quine"+(N+1)).getMethod("main",a.getClass()).invoke(null,new Object[]{new String[]{}});}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment