I have a little quiz that I cannot solve by myself. I want to build a program that will print its own source code with java. Anyone knows how to do this? Like this example:
public class SourcePrint {
private static final long serialVersionUID = 1L;
public void test(){
System.out.println("Hi I'm test");
}
public static void main(String[] args) {
new SourcePrint().test();
}
}
when we run this, the output would be same like this:
public class SourcePrint {
private static final long serialVersionUID = 1L;
public void test(){
System.out.println("Hi I'm test");
}
public static void main(String[] args) {
new SourcePrint().test();
}
}
I don't know how to do this. Anybody know the solution or at least the hint? This is not the decompiler, the quiz maker told me the hint is "STATIC".
A quine is a program which prints its own listing. This means that when the program is run, it must print out precisely those instructions which the programmer wrote as part of the program (including, of course, the instructions that do the printing, and the data used in the printing).
out. println(): This method prints the text on the console and the cursor remains at the start of the next line at the console.
http://en.wikipedia.org/wiki/Quine_%28computing%29
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With